I had setup bytecode instrumentation to enable nullable lazy property loading for hibernate 4.3. After the migration to hibernate 5.2.1 the lazy loading behaviour seems to be broken.
The configuration I have is:
For instrumentation, I've disabled everything I could and only left the lazy loading instrumentation {code:xml|title:pom.xml} <plugin> <groupId>org.hibernate.orm.tooling</groupId> <artifactId>hibernate-enhance-maven-plugin</artifactId> <version>${hibernate.version}</version> <executions> <execution> <configuration> <failOnError>true</failOnError> <enableLazyInitialization>true</enableLazyInitialization> <enableDirtyTracking>false</enableDirtyTracking> <enableAssociationManagement>false</enableAssociationManagement> <enableExtendedEnhancement>false</enableExtendedEnhancement> </configuration> <goals> <goal>enhance</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> <version>${jta.version}</version> </dependency> </dependencies> </plugin> {code}
Entity containing the lazy loaded field {code:java|title=Lazy loaded field declaration} @Entity @Table("BLAH") class ContainsALazyNullableField {
... @OneToOne(fetch = FetchType.LAZY, optional = true) @LazyToOne(LazyToOneOption.NO_PROXY) @PrimaryKeyJoinColumn @LazyGroup("groupName") private TempTableEntity tempTableEntity; ... } {code}
{code:java|title=Type of the lazy field} @Entity @Table(name = "TEMP_TABLE") public class TempTableEntity {
@Id @Column(name = " REGISTRATION_ID LAZY_FIELD_CONTAINER_ID ") private String registrationId lazyFieldContainerId ;
@Column(name = "SORT_ORDER") private int sortOrder;
... } {code}
What I get is this: {code} javax.persistence.EntityNotFoundException: Unable to find com.aa.TempTableEntity with id 0000019d-b151-4336-90a5-d41c499f7d30
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$JpaEntityNotFoundDelegate.handleEntityNotFound(EntityManagerFactoryBuilderImpl.java:157) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:262) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1213) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1096) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:639) at org.hibernate.type.EntityType.resolve(EntityType.java:431) at org.hibernate.type.EntityType.nullSafeGet(EntityType.java:262) at org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyPropertiesFromDatastore(AbstractEntityPersister.java:1063) at org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyProperty(AbstractEntityPersister.java:991) at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor$1.doWork(LazyAttributeLoadingInterceptor.java:105) at org.hibernate.bytecode.enhance.spi.interceptor.Helper.performWork(Helper.java:97) at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.loadAttribute(LazyAttributeLoadingInterceptor.java:76) at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.fetchAttribute(LazyAttributeLoadingInterceptor.java:72) at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.intercept(LazyAttributeLoadingInterceptor.java:61) at org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor.readObject(LazyAttributeLoadingInterceptor.java:296) at com.aa.ContainsALazyNullableField.$$_hibernate_read_someOtherLazyField(ContainsALazyNullableField.java) at com.aa.ContainsALazyNullableField.getTempTableEntity(ContainsALazyNullableField.java:477) {code} |
|