spring-projects / spring-projects/spring-data-mongodb
Update of entity with @Version and custom-converted, nested document fails [DATAMONGO-1281]
@odrotbohm is already working on this.
Since Dec 30, 2020.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
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
@Versionproperty
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.