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;
}

Activity

Show:

Steve Ebersole May 20, 2015 at 7:36 AM

I've already coordinated with the appropriate folks on HHH-9806, so lets continue discussion there

Vlad Mihalcea September 11, 2014 at 6:47 AM

I tested it with 4.3.6. Unfortunatelly, I couldn't supply a test case since it's more like an Hibernate inner-working issue.

I found this issue (and neither the new enhancer couldn't fetch the dirty properties, so it fell back to the default deep-comparison algorithm)
while writing this blog post:

http://vladmihalcea.com/2014/09/08/hibernate-bytecode-enhancement/

You can clone my project from GitHub, this is the actual test I've been running:

https://github.com/vladmihalcea/hibernate-master-class/blob/master/ant-bytecode-enhance/src/test/java/com/vladmihalcea/hibernate/masterclass/laboratory/flushing/AntBytecodeEnhancedTest.java

Former user September 10, 2014 at 11:11 PM

Does this happen in 4.3.6?

Duplicate

Details

Assignee

Reporter

Priority

Created September 6, 2014 at 8:21 PM
Updated May 20, 2015 at 7:36 AM
Resolved May 20, 2015 at 7:36 AM

Flag notifications