mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-03-02 07:49:23 +00:00
HHH-13380 Bytecode enhanced entities might throw LazyInitializationException from custom equals/hashcode implementations
Apparently we trigger the need to invoke equals/hashcode methods on managed entities just before the Session is attached to the BytecodeLazyAttributeInterceptor
This commit is contained in:
parent
e73b05100d
commit
c1f9b9dda4
@ -16,11 +16,13 @@
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata;
|
||||
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.Assigned;
|
||||
@ -702,12 +704,25 @@ public final Object instantiate(Serializable id) throws HibernateException {
|
||||
@Override
|
||||
public final Object instantiate(Serializable id, SharedSessionContractImplementor session) {
|
||||
Object result = getInstantiator().instantiate( id );
|
||||
linkToSession( result, session );
|
||||
if ( id != null ) {
|
||||
setIdentifier( result, id, session );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void linkToSession(Object entity, SharedSessionContractImplementor session) {
|
||||
if ( session == null ) {
|
||||
return;
|
||||
}
|
||||
if ( entity instanceof PersistentAttributeInterceptable ) {
|
||||
final BytecodeLazyAttributeInterceptor interceptor = getEntityMetamodel().getBytecodeEnhancementMetadata().extractLazyInterceptor( entity );
|
||||
if ( interceptor != null ) {
|
||||
interceptor.setSession( session );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object instantiate() throws HibernateException {
|
||||
return instantiate( null, null );
|
||||
|
Loading…
x
Reference in New Issue
Block a user