Demo is attached.
Run the code with & without byte code enhancement.
* NOTE:* Problem with non-enhanced mode is that all optional one to ones are fetched as soon as the root entity is fetched *
*Post* has two OneToOne relationships.
1. *AdditionalDetails* 2. *OptionalOneToOneDetails*
Without enhancement, the initialization of *AdditionalDetails* relationship works fine.
{code:java} Hibernate.initialize(post.getAdditionalDetails()); {code}
After enhancing the bytecode, I get this exception
{code:java} INFO: HHH000327: Error performing load command : org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.acme.OptionalOneToOneDetails#1] Exception in thread "main" org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.acme.OptionalOneToOneDetails#1] at org.hibernate.boot.internal.StandardEntityNotFoundDelegate.handleEntityNotFound(StandardEntityNotFoundDelegate.java:28) 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:1237) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1120) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:646) 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:1091) at org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyProperty(AbstractEntityPersister.java:1002) 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.acme.Post.$$_hibernate_read_additionalDetails(Post.java) at com.acme.Post.getAdditionalDetails(Post.java:44) at com.acme.Main.main(Main.java:77) {code} |
|