Hibernate / EclipseLink Interview questions
How do you troubleshoot lazy loading failures caused by missing weaving in EclipseLink?
A common symptom is a lazy relationship that either loads eagerly regardless of the fetch = FetchType.LAZY annotation, or throws an error when accessed outside an active persistence context, both of which usually trace back to weaving not actually being applied to the deployed entity classes.
- Confirm weaving is enabled - check that
eclipselink.weavingisn't set tofalseinpersistence.xml; it defaults to enabled, but is sometimes disabled during debugging and left that way. - Check for a Java agent (dynamic weaving) - confirm the
-javaagentflag pointing at EclipseLink's weaving agent is actually present on the JVM's startup command, or that the application server's own weaving support is active. - Check the build for static weaving - if relying on static weaving, confirm the Ant task or Maven/Gradle plugin actually ran and its output classes (not the unwoven originals) are what's deployed.
- Inspect the deployed class file - a woven class contains extra synthetic fields and methods (like
_persistence_...prefixed members); their absence confirms weaving didn't run against that build artifact. - Check for classes loaded before weaving could apply - dynamic weaving only affects classes loaded after the agent registers; entities loaded very early in startup, before the persistence unit initializes, can end up unwoven.
Once weaving is confirmed active, lazy fields behave transparently again; the fallback indirection EclipseLink otherwise uses is functional but noticeably less efficient, which is often the first clue something is wrong even before an outright error appears.
More Related questions...