HHH-7237 - Inline natural-id synchronization doesn't consider reattached objects

This commit is contained in:
Steve Ebersole 2012-04-24 11:23:22 -05:00
parent 76504f128f
commit 946f0297bb
1 changed files with 20 additions and 9 deletions

View File

@ -71,6 +71,7 @@ import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.PersistenceContext.NaturalIdHelper; import org.hibernate.engine.spi.PersistenceContext.NaturalIdHelper;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
@ -3982,7 +3983,6 @@ public abstract class AbstractEntityPersister
// } // }
public void afterReassociate(Object entity, SessionImplementor session) { public void afterReassociate(Object entity, SessionImplementor session) {
//if ( hasLazyProperties() ) {
if ( getEntityMetamodel().getInstrumentationMetadata().isInstrumented() ) { if ( getEntityMetamodel().getInstrumentationMetadata().isInstrumented() ) {
FieldInterceptor interceptor = getEntityMetamodel().getInstrumentationMetadata().extractInterceptor( entity ); FieldInterceptor interceptor = getEntityMetamodel().getInstrumentationMetadata().extractInterceptor( entity );
if ( interceptor != null ) { if ( interceptor != null ) {
@ -3998,15 +3998,26 @@ public abstract class AbstractEntityPersister
fieldInterceptor.dirty(); fieldInterceptor.dirty();
} }
} }
if ( hasNaturalIdentifier() ) {
final Serializable id = getIdentifier( entity, session ); handleNaturalIdReattachment( entity, session );
final NaturalIdHelper helper = session.getPersistenceContext().getNaturalIdHelper(); }
helper.cacheNaturalIdCrossReferenceFromLoad( // TODO rename cacheNaturalIdCrossReferenceFromLoad ?
this, private void handleNaturalIdReattachment(Object entity, SessionImplementor session) {
id, if ( ! hasNaturalIdentifier() ) {
helper.extractNaturalIdValues( getPropertyValues(entity), this ) return;
);
} }
if ( getEntityMetamodel().hasImmutableNaturalId() ) {
return;
}
final Serializable id = getIdentifier( entity, session );
final NaturalIdHelper helper = session.getPersistenceContext().getNaturalIdHelper();
helper.cacheNaturalIdCrossReferenceFromLoad( // TODO rename cacheNaturalIdCrossReferenceFromLoad ?
this,
id,
helper.extractNaturalIdValues( getPropertyValues(entity), this )
);
} }
public Boolean isTransient(Object entity, SessionImplementor session) throws HibernateException { public Boolean isTransient(Object entity, SessionImplementor session) throws HibernateException {