Dirty Checking not working as expected with bytecode enhancement
Description
Activity
Andrea Boriero July 2, 2024 at 11:59 AM
Hi @Piotr Blasiak, this issue is related to dirty checking and what you are mentioning seems not specifically related to it.
I tried the test provided by @Ant Kutschera and it passes so I’m going to close this issue, please create a new one with a reproducer for you issue.
Thanks
Piotr Blasiak May 22, 2024 at 7:43 AMEdited
I can confirm this issue exists on 6.5.0.Final as well - I am trying to create a sample project. Essentially when updating an entity with boolean field changed, it does not seem to mark it as dirty when using the enhancer but it does so when not using the enhancer. Also it does not matter if enableDirtyTracking
is set to true or false - simply using the enhancer is enough to break this.
Andrea Boriero April 3, 2024 at 1:23 PM
Hi @Ant Kutschera ,
this issue should be fixed by https://github.com/hibernate/hibernate-orm/pull/8091 .
Ant Kutschera April 2, 2024 at 8:57 PMEdited
I added a unit test to a zip on the quarkus bug and sure enough, with bytecode enhancement turned on, I get the same problem - see https://github.com/quarkusio/quarkus/issues/39792#issuecomment-2033082128 .
Is that by design? If yes, how are you supposed to send a large graph of objects to the server and have only the changed ones updated?
I am implementing an application using Quarkus 3.9.1 and Hibernate 6.4.4.Final and I came across something that suprised me. When I send JSON to the server, which has the same state as that of the database, and I map that data into a new and detached entity object, and then call EntityManager#merge with that object, Hibernate generates an update statement.
Hibernate executes a select statement to fetch the latest data from the database (all good and expected).
I assumed that dirty checking would then determine that the object has no changes and so it would not generate an update statement. But without fail, one is generated.
I created a unit test which uses plain vanilla Hibernate without Quarkus, and that confirmed that normally, no update statement is generated. But there is a difference and that is that the unit test doesn’t use bytecode enhancement.
Perhaps my expectation is wrong, and when using bytecode enhancement, and when merging detached objects, it is normal to always generate an update statement? Please confirm.
The Quarkus Bug is: https://github.com/quarkusio/quarkus/issues/39792