Skip to content

Update of entity with @Version and custom-converted, nested document fails [DATAMONGO-1281] #2199

Open
@spring-projects-issues

Description

@spring-projects-issues

Lars Hvile opened DATAMONGO-1281 and commented

I've just stumbled across a bug related to custom converters & document-updates. It seems like spring-data-mongo generates invalid update statements in some cases (depending on the interface of the converted type). The attached Gist contains a testcase which should work, but instead ends up failing with the following exception on line 57 (the 2nd save())

Caused by: java.lang.IllegalArgumentException: Document field names can't have a . in them. (Bad Key: 'date.year')
	at com.mongodb.DBCollection.validateKey(DBCollection.java:1842)
	at com.mongodb.DBCollection._checkKeys(DBCollection.java:1802)
	at com.mongodb.DBCollection._checkValue(DBCollection.java:1825)

Steps to reproduce:

  • Read/write converters for SomeInterface => DBObject & DBObject => SomeInterface
  • The converter produces a "camelCase" property in the DBObject which happens to match a property in SomeInterface. ("LocalDate getDate()" vs "dateYear" in the Gist)
  • The top-level document has a @Version property

This bug is kind of sneaky as inserts will work just fine, but updates may fail depending on the interface of the converted type. I.e. this is both tricky to catch in tests, and may pop up in production simply by doing some seemingly harmless refactoring.

(I've also noticed something similar regarding the '_id' property.. Inserting a nested object with an 'id' property works, but an update renames it to '_id' in some cases. There seems to be some issues with updates in general...)


Affects: 1.6.3 (Evans SR3)

Reference URL: https://gist.github.com/larshvile/31feaaada2a9b2abcff5

Metadata

Metadata

Assignees

Labels

in: mappingMapping and conversion infrastructuretype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions