We're updating the issue view to help you get more done. 

org.hibernate.engine.spi.EntityEntry doesn't use bytecode enhancement dirty checking

Description

When using the ant-style bytecode enhancement:

<taskdef name="instrument"
classname="org.hibernate.tool.instrument.javassist.InstrumentTask">
<classpath>
<path refid="maven.dependency.classpath"/>
<path refid="maven.plugin.classpath"/>
</classpath>
</taskdef>

the org.hibernate.bytecode.instrumentation.spi.AbstractFieldInterceptor is used to manage entity dirtiness.

Even if the entity is marked dirty, Hibernate cannot use this info and therefore it falls-back to the deep-comparison default algorithm.

This is because the org.hibernate.engine.spi.EntityEntry#isUnequivocallyNonDirty method will never check the interceptor's dirtiness flag, whenever we have a mutable entity:

if ( getPersister().hasMutableProperties() ) {
return false;
}

if ( getPersister().getInstrumentationMetadata().isInstrumented() ) {
// the entity must be instrumented (otherwise we cant check dirty flag) and the dirty flag is false
return ! getPersister().getInstrumentationMetadata().extractInterceptor( entity ).isDirty();
}

This was changed since 4.1.4 since in 4.1.3 (http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate/hibernate-core/4.1.3.Final/org/hibernate/engine/spi/EntityEntry.java#EntityEntry.isUnequivocallyNonDirty%28java.lang.Object%29) this is how this method looked like:

@SuppressWarnings( {"SimplifiableIfStatement"})
private boolean isUnequivocallyNonDirty(Object entity) {
if ( getPersister().getInstrumentationMetadata().isInstrumented() ) {
// the entity must be instrumented (otherwise we cant check dirty flag) and the dirty flag is false
return ! getPersister().getInstrumentationMetadata().extractInterceptor( entity ).isDirty();
}

final CustomEntityDirtinessStrategy customEntityDirtinessStrategy =
persistenceContext.getSession().getFactory().getCustomEntityDirtinessStrategy();
if ( customEntityDirtinessStrategy.canDirtyCheck( entity, getPersister(), (Session) persistenceContext.getSession() ) ) {
return ! customEntityDirtinessStrategy.isDirty( entity, getPersister(), (Session) persistenceContext.getSession() );
}

return false;
}

Environment

None

Status

Assignee

Unassigned

Reporter

Vlad Mihalcea

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Priority

Major