Fixed
Details
Assignee
Luis BarreiroLuis BarreiroReporter
Gábor VargaGábor Varga(Deactivated)Labels
Components
Priority
Major
Details
Details
Assignee
Luis Barreiro
Luis BarreiroReporter
Gábor Varga
Gábor Varga(Deactivated)Labels
Components
Priority
Created February 22, 2016 at 3:49 PM
Updated March 15, 2016 at 2:10 AM
Resolved February 26, 2016 at 5:57 PM
When the in-line dirty tracking bytecode enhancement is enabled (the
enableDirtyTracking
parameter of thehibernate-enhance-maven-plugin
's configuration istrue
), and an entity with an@Embeddable
property is constructed by setting this field tonull
in the constructor, aNullPointerException
is thrown from the following location:java.lang.NullPointerException at com.example.model.MyTestEntity.$$_hibernate_write_myTestEmbeddable(MyTestEntity.java) at com.example.model.MyTestEntity.<init>(MyTestEntity.java:37)
The interesting code snippets in the bytecode enhanced entity are as follows:
private MyTestEmbeddable myTestEmbeddable; @Transient private transient PersistentAttributeInterceptor $$_hibernate_attributeInterceptor; public MyTestEntity(Long id, Integer myTestInteger, MyTestEmbeddable myTestEmbeddable) { this.$$_hibernate_write_id(id); this.$$_hibernate_write_myTestInteger(myTestInteger); this.$$_hibernate_write_myTestEmbeddable(myTestEmbeddable); } public PersistentAttributeInterceptor $$_hibernate_getInterceptor() { return this.$$_hibernate_attributeInterceptor; } public void $$_hibernate_write_myTestEmbeddable(MyTestEmbeddable myTestEmbeddable) { // #1 if (this.myTestEmbeddable != null) { ((CompositeTracker)this.myTestEmbeddable).$$_hibernate_clearOwner("myTestEmbeddable"); } // #2 if (!EqualsHelper.areEqual((Object)this.myTestEmbeddable, (Object)myTestEmbeddable)) { this.$$_hibernate_trackChange("myTestEmbeddable"); } // #3 MyTestEmbeddable myTestEmbeddable2 = myTestEmbeddable; // #4 if (this.$$_hibernate_getInterceptor() != null) { myTestEmbeddable2 = (MyTestEmbeddable)this.$$_hibernate_getInterceptor().writeObject((Object)this, "myTestEmbeddable", (Object)this.myTestEmbeddable, (Object)myTestEmbeddable); } // #5 this.myTestEmbeddable = myTestEmbeddable2; // #6 Object var4_3 = null; // #7 ((CompositeTracker)this.myTestEmbeddable).$$_hibernate_setOwner("myTestEmbeddable", (CompositeOwner)this); // #8 this.$$_hibernate_trackChange("myTestEmbeddable"); }
The
myTestEmbeddable
argument of the constructor isnull
, so$$_hibernate_write_myTestEmbeddable()
is called with anull
argument. The$$_hibernate_attributeInterceptor
field is not initialized in the constructor, so$$_hibernate_getInterceptor()
always returnsnull
. Because of this, the conditional code #4 is not run. In #3, thenull
argument is written to a temporary variable, and then in #5, it's written to themyTestEmbeddable
field. Afterwards in #7, it's being cast toCompositeTracker
, and its$$_hibernate_setOwner
is called, while the field is stillnull
. I think this is what throws theNullPointerException
.The Java source files of the original and bytecode enhanced
@Entity
and@Embeddable
classes are attached to this ticket.The
hibernate-enhance-maven-plugin
configuration was as follows:<configuration> <enableLazyInitialization>true</enableLazyInitialization> <enableDirtyTracking>true</enableDirtyTracking> <enableAssociationManagement>false</enableAssociationManagement> <enableExtendedEnhancement>false</enableExtendedEnhancement> </configuration>
The description above is valid for Hibernate 5.0.8, but the same
NullPointerException
occurs when using Hibernate 5.1.0.