-
Hello all, I am working on migrating a legacy Java 11, Spring 5/data/jpa, and EclipseLink 2.7 cloud server application to Java 17, Spring 6.1.x, and EclipseLink 4.0.x. We use load-time-weaving with aspectj and spring-instrument agents. The specific dependency versions currently in use are:
We use single table multitenancy and heavily rely on FetchType.LAZY for entity relationship mappings (
With the updated dependencies, during server start-up EclipseLink reports the following warning for most/all of our entities that use FetchType.LAZY:
Previously when we were running Spring 5/EclipseLink 2.7 no warnings of this type were logged. This has led me to believe that the weaving of entity classes is not working correctly, and I have not been able to figure out why. During server start up, we are also seeing exceptions such as:
I've been able to temporarily get around this issue by deleting the entity relationship mappings/joins out of the entity classes and replacing them with external manual database operations. We only have couple entities that are being accessed while the server is starting up which completely halts it from launching. However this is only a bandaid fix and does not fix the underlying problem. Certain API's/web pages can be accessed on our site while the user is not logged in and thus not yet associated to a tenant id. In these contexts the 'eclipselink.tenant-id' jpa property is null. When fetching an entity that has a relationship with another entity annotated
We do have a custom implementation of EntityManagerFactory that sets the 'eclipselink.tenant-id' property. I have hit a breakpoint where the exception is being thrown and confirmed that the property does exist in the jpa property map, but it is null (as expected) due to the user being in a tenantless context. I believe the above error is caused by lazy loading being broken, so associated multitenant entities are being eagerly fetched and then failing due to the null tenant id when they were not being fetched previously due to the lazy fetching. We do not configure EclipseLink through persistence.xml and instead use Java configuration via Spring's LocalContainerEntityManagerFactoryBean:
Our entities are defined like this and share a BaseEntity abstract parent class annotated with @MappedSuperclass:
Apologies for the long-winded post, but I was hoping someone might have some ideas on what is causing our issue with entity weaving and FetchType.LAZY. I am not sure what has changed in between these dependency versions that have caused this issue, and I've been unable to find useful migration documentation between EclipseLink 2.7 and 4.0.x. We are seeing the same issue on EclipseLink 3.x. Thank you for your time, Andrew |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Maybe this is not related, but we did some AspectJ related fix in #1841
try to disable EclipseLink |
Beta Was this translation helpful? Give feedback.
-
Just wanted to give an update on this, after much trial and tribulation one of our senior developers finally figured out what was causing the issue. Spring was wiring up our JPA repositories too early causing the associated entities to be missed by the Eclipselink weaver. After changing around the way things were getting configured and wired up the weaving issues went away. For reference, the issue ended up being very similar to this old issue reported in the Spring jpa framework: |
Beta Was this translation helpful? Give feedback.
Just wanted to give an update on this, after much trial and tribulation one of our senior developers finally figured out what was causing the issue. Spring was wiring up our JPA repositories too early causing the associated entities to be missed by the Eclipselink weaver. After changing around the way things were getting configured and wired up the weaving issues went away.
For reference, the issue ended up being very similar to this old issue reported in the Spring jpa framework:
spring-projects/spring-data-jpa#1585