ArrayIndexOutOfBoundsException in DirtyHelper.isModified()

I am working through upgrading a large repo from Hibernate 5.4 to Hibernate 6.0, and I am running into the following issue.

During an auto flush, one of my entities is passing through what looks like a new class introduced in Hibernate 6 called DirtyHelper. In a method called isModified(), there is a comparison between the “previous state” and the “current state” of the object, each of which is just an array of property values.

However, the number of array entries in each array doesn’t match. In this specific case, my previous state contains 28 entries and my current state contains 32 entries. This leads to an ArrayIndexOutOfBoundsException as it loops through the current state, and eventually runs out of entries to compare in the previous state.

What I’ve managed to determine is that the “previous state” is missing entries for columns that have been marked with the annotation @OneToOne(mappedBy = "myDomainObject"). When debugging internally, this appears to be deliberate.

Does anybody have any clues as to how I might have triggered this issue?

Try using Hibernate ORM 6.4.0.Final and if that error persists, please try to create a reproducer with our test case template (hibernate-test-case-templates/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/ at main · hibernate/hibernate-test-case-templates · GitHub) and if you are able to reproduce the issue, create a bug ticket in our issue tracker( and attach that reproducer.

Apologies this was actually against 6.4.0.Final, so I’ll try to reproduce with the template.

On further analysis, the trigger appears to be when the object in the one to one relationship is created in one transaction, detached, and reused in a second transaction where the parent object is saved, and has a “SAVE_UPDATE” cascade.

In this scenario, the auto flush operation attempts to reattach it to the session, and this is where the dirty check gets into trouble.

Issue has been reproduced. Bug created:

1 Like