-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hibernate dirty property false positives #30234
Comments
In case it matters, my entites are in a separately built jar rather than being part of the quarkus app proper. |
Hey @Traivor , thanks for the report. There are multiple things at play here, and dirty checking obviously works in some situations (the ones from our tests, at least), so it's a bit hard to understand what went wrong in your case. Can you please provide a simple reproducer? Thanks. |
@yrodiere Not the op of this issue, but I can also reproduce problems with dirty checking since 2.14.1.Final (but not e.g. 2.13.3.Final). Here is a reproducer:
|
I tested a few different versions. Version 2.13.3.Final and down are not affected. 2.13.4.Final included an hibernate update. Maybe it is related. |
@yrodiere No update gets done if I annotate the field as (correct behaviour)
I believe this might be caused by hibernate/hibernate-orm#5461 |
Thank you! I have no idea when I might have had time to create a repropducer. |
A possible workaround is to circumvent the in-built dirty check of hibernate, and write our own:
This obiously does not handle every possible case for the dirty detection, but works in my small reproducer app for now. |
I concur, that's the most likely cause. We started using that patch in Quarkus with #28881 , in Quarkus 2.13.4. I'm still having a look at the reproducer, I'll probably have to convert it to a Quarkus-free reproducer for the Hibernate ORM team to have a look. |
Reported upstream as https://hibernate.atlassian.net/browse/HHH-16049 Thanks @Postremus for your help! |
My trial on this issue lead to compile time byte-code enhancement (plugin: https://docs.jboss.org/hibernate/orm/5.0/topical/html/bytecode/BytecodeEnhancement.html |
@ribizli Be aware that if you don't use the exact same version of Hibernate ORM for compile-time bytecode enhancement as the version of Hibernate ORM used at runtime, you may avoid this particular bug, but you will run into many other bugs caused by incompatibility. |
@yrodiere Is there any plan for a new ORM 5.6 release with this bugfix? |
I think Sanne started working on some performance improvements, I don't know if he's done, but after that yes we'll probably release another 5.6. @Sanne any objection to releasing 5.6 soon? |
sure, I'm long done with the 5.6 changes and moved on to tuning ORM 6 - we could release a 5.6 anytime on the Hibernate side. A bigger question is if there will actually be a Quarkus release to include the new version: with Quarkus 3.0 being the next version and it being expected to be based on Hibernate ORM 6, the 5.x upgrade would need to be done in a micro maintenance. But let's release ORM 5 either way, then at very least @Postremus has the option to override the version and we can see if there's going to be an upgrade in Quarkus or not - plans are flexible and at least we'll be ready for it. This could be useful for benchmarks too. |
Fixes quarkusio#30234 (cherry picked from commit 41866da)
I am pretty sure that I have this issue in 3.9.1. Still testing... |
@maxant I would recommend to open another issue with a simple reproducer. |
In case anyone stumbles over this and needs the DirtyCheckInterceptor above, a) I think it has two bugs and b) it is kind of deprecated in hibernate 6. a) bug 1?
That should test a) bug 2?
I noticed that when a ManyToOne field is encounted, it is ignored in the original code. Above is an additional check which ensures that the foreign key hasn't changed and if it has, marks the field as changed. b) this works with hibernate 6:
@Postremus where did you get that code from orginally? It would be cool if it was in a library, or indeed hibernate itself, so that I can be used if required. I think that when bytecode enhancement is turned on, dirty checking doesn't work properly when merging detached objects and forces an update statement even if the object is unchanged compared to the DB. Quarkus uses bytecode by default. |
Describe the bug
Beginning with Quarkus 2.14.1.Final and continuing through 2.15.2.Final, hibernate is detecting properties as dirty even if they have been set to the same value that is already in the entity.
eg
var myEntity = em.find(MyEntity.class, id);
myEntity.setProperty(myEntity.getProperty());
Will result in an update sent to the db. Envers will actually NOT store an audit unless there is also an update timestamp that gets updated on persist such as one managed by @UpdateTimestamp. Envers is how I found this was happening since I do have such a timestamp implemented.
Turning hibernate logs up to 11, these are the only interesting entries I get.
2.14.0.Final and 2.13.3.Final do not exhibit this behavior.
Expected behavior
If an entity property is set to the same value it already contained, the entity should not be marked dirty and updated in the database.
Actual behavior
Extra updates (and potentially envers audits) are sent to the database.
How to Reproduce?
No response
Output of
uname -a
orver
Linux masergyball 6.0.15-300.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Dec 21 18:33:23 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Output of
java -version
openjdk version "11.0.17" 2022-10-18 OpenJDK Runtime Environment (Red_Hat-11.0.17.0.8-1.fc37) (build 11.0.17+8) OpenJDK 64-Bit Server VM (Red_Hat-11.0.17.0.8-1.fc37) (build 11.0.17+8, mixed mode, sharing)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.14.1.Final - 2.15.2.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0) Maven home: /home/hcampbell/tools/maven Java version: 11.0.17, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.17.0.8-1.fc37.x86_64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "6.0.15-300.fc37.x86_64", arch: "amd64", family: "unix"
Additional information
No response
The text was updated successfully, but these errors were encountered: