Spring-data for mongodb treats fields named "id" special: http://static.springsource.org/spring-data/data-mongo/docs/1.0.0.M5/reference/html/#d0e1508, in that it tries to map a field named id to the _id field in MongoDB. Is there a way to disable this behavior? I'd like the mongodb ObjectId only mapped to fields with the explicit @Id
annotation. Currently I have fields named id in mongodb, and this is not something I can change, and I'm finding it to be near impossible to get spring-data to map the correct id value back into the pojo.
The current version of Spring Data MongoDB (1.2.0.RELEASE) would reject a class with multiple id properties (annotated or default ones). If you think we should get more lenient on this (ignoring all default properties if a property is explicitly annotated with @Id
) feel free to open a ticket in our JIRA. The current behavior is implemented to eagerly discover potential misconfiguration that might have occurred when moving from default mappings to explicitly annotated.