Spring data mongodb appears to force a property called 'id' to map to mongodb '_id'. Unfortunately, this is not the behaviour I need. I cannot rename my property. I want to keep my existing property 'id' as a field and introduce a new property 'docId' to map to mongodb '_id'. This is necessary to maintain compatibility with an existing hyperjaxb3-generated domain model that is also persisted to a relational database via hibernate.
The relevant lines of code from 1.1.0.RELEASE that affect me are...
QueryMapper.java:47
BasicMongoPersistentProperty.java:53Code:private static final List<String> DEFAULT_ID_NAMES = Arrays.asList("id", "_id");
There does not seem to be a way for me to injected or customise the behaviour I need. However, if I override the classes in my project and edit the above lines to exclude 'id', then everything works as I need it to. I then extend AbstractMongoEventListener onAfterConvert/onBeforeSave to map as I need. Using the listener allows me to keep using the existing deep mapping in MappingMongoConverter.Code:SUPPORTED_ID_PROPERTY_NAMES.add("id");
Is there a more elegant solution?
Shall I raise an improvement JIRA or does one already exist (a quick search found nothing)?


Reply With Quote