| Demo is attached. Ruin the code by enabling byte code enhancement & without byte code enhancement. Post has two OneToOne children. 1. AdditionalDetails 2. OptionalOneToOneDetails Without bytecode enhancement, the initialisation of AdditionalDetails relationship works fine. Hibernate.initialize(retrievedPost.getAdditionalDetails()); Without it, I get this exception
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)
|