spring-projects / spring-projects/spring-data-mongodb

Lazy DBref does not work with kotlin data classes having an immutable id property [DATAMONGO-2654]

Open
#3,507 0 comments 0 reactions 1 assignee View on GitHub

@christophstrobl is already working on this.

Since Dec 30, 2020.

in: kotlin in: mapping type: bug
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Thorsten Hake opened DATAMONGO-2654 and commented

Referring with @DBRef(lazy=true) to a kotlin data class having an immutable id property does not work as expected. During the initialization of the ID property, the whole data class will be loaded from MongoDB. The developer won't be notified about this behavior.

The root cause of this is the usage of the copy method of kotlin data classes to set the ID property. Upon calling the copy method of the data class, the data class will access all properties (except the id) of the generated LazyLoadingProxy proxy. The LazyLoadingInterceptor will intercept those calls to the properties and loads the whole kotlin data class.

The property accessor generated by ClassGeneratorPropertyAccessorFactory will by default call the copy method for immutable kotlin data properties (see PropertyAccessorClassGenerator.visitSetProperty0).

 


No further details from DATAMONGO-2654

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.