jmix-framework / jmix

Jmix framework
https://www.jmix.io
Apache License 2.0
561 stars 118 forks source link

Add org.springframework.data.annotation.Transient annotation when enhancing entities #1827

Open glebfox opened 1 year ago

glebfox commented 1 year ago

Currently io.jmix.gradle.TransientAnnotationEnhancingStep adds only jakarta.persistence.Transient annotation.

For some DB intergrations it is needed to add different annotations in order to ignore some attributes from been precessed, e.g.: when working with mongo using spring-boot-starter-data-mongobd, it is needed to add org.springframework.data.annotation.Transient annotation. Without it, mapping our DTO to Mongo document results in StackOverflowException because of _jmixEntityEntry field, which refers on source (entity itself) which refers on _jmixEntityEntry which refers on source (entity itself) which refers on... boom.


mongodb-sample.zip

Case:

  1. Run docker compose up from project's docker directory
  2. Start the app
  3. Try to create a new Product

AR:

Caused by: java.lang.StackOverflowError: null
    at java.base/java.util.HashMap.get(HashMap.java:556) ~[na:na]
    at org.springframework.data.mapping.model.ClassGeneratingPropertyAccessorFactory.getPropertyAccessor(ClassGeneratingPropertyAccessorFactory.java:87) ~[spring-data-commons-2.7.10.jar:2.7.10]
    at org.springframework.data.mapping.model.InstantiationAwarePropertyAccessorFactory.lambda$getPropertyAccessor$0(InstantiationAwarePropertyAccessorFactory.java:46) ~[spring-data-commons-2.7.10.jar:2.7.10]
    at org.springframework.data.mapping.model.InstantiationAwarePropertyAccessor.getProperty(InstantiationAwarePropertyAccessor.java:157) ~[spring-data-commons-2.7.10.jar:2.7.10]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:882) ~[spring-data-mongodb-3.4.10.jar:3.4.10]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:864) ~[spring-data-mongodb-3.4.10.jar:3.4.10]
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:998) ~[spring-data-mongodb-3.4.10.jar:3.4.10]
gorbunkov commented 8 months ago

We can add a setting for a gradle plugin which annotations to add.