Hello,
i am encountering an issue after enabling Hibernate bytecode enhancements in my project. In particular, the issue is related to dirty checking in embeddables.
In any given entity, if i set a new embeddable equivalent to the one currently set in the entity, the embedded attribute is set as dirty.
I checked the generated code for the write method, it seems that writing an embeddable indeed always sets the attribute as dirty, regardless of equality check. This is the generated code in Hibernate 6.6.7.Final as a reference:
public void $$_hibernate_write_artifact(ArtifactCoordinates var1) {
if (this.artifact != null) {
ManagedTypeHelper.asCompositeTracker(this.artifact).$$_hibernate_clearOwner("artifact");
}
if (!InlineDirtyCheckerEqualsHelper.areEquals(this, "artifact", var1, this.artifact)) {
this.$$_hibernate_trackChange("artifact");
}
if (this.$$_hibernate_getInterceptor() != null) {
this.artifact = (ArtifactCoordinates)this.$$_hibernate_getInterceptor().writeObject(this, "artifact", this.artifact, var1);
} else {
this.artifact = var1;
}
if (this.artifact != null) {
ManagedTypeHelper.asCompositeTracker(this.artifact).$$_hibernate_setOwner("artifact", this);
}
this.$$_hibernate_trackChange("artifact");
}
I don’t understand why $$_hibernate_trackChange
is always called at the end of the method, i expected to be called only in case of inequality (the second IF block).
My embeddables implement equals()
, but are always flagged as dirty, so an update is triggered even if not necessary.
Can someone clarify this behavior?
Thanks.