-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 ORM update issue since 3.13.0 #42902
Comments
/cc @FroMage (panache), @loicmathieu (panache) |
Seems similar to #42322. I think this is related to https://github.com/quarkusio/quarkus/wiki/Migration-Guide-3.13#auto-flush-optimization Previously Hibernate ORM in Quarkus was flushing indiscriminately before a query, leading to performance issues, especially compared to pretty much every other framework out there, where that sort of aggressive flushing is opt-in. We changed that to align on the rest of the ecosystem -- and on how Hibernate ORM expects to be used. Your problem would hint at Hibernate ORM not auto-detecting that a flush is needed -- possibly a limitation of auto-flush, which you could try reporting upstream to get improved detection (with a reproducer based on https://github.com/hibernate/hibernate-test-case-templates/blob/main/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/QuarkusLikeORMUnitTestCase.java, ideally). EDIT: In the meantime, the easiest workaround would be to add an explicit flush, of course. EDIT2: Second workaround to revert to the old behavior in 3.12 (and accept the performance hit that was present then, throughout your entire application): // Put this in an `@ApplicationScoped` bean somewhere.
void onBeginTransaction(@Observes @Initialized(TransactionScoped.class) Object event, Session session) {
session.setHibernateFlushMode(FlushMode.ALWAYS);
} |
Thanks a lot @yrodiere :) |
Created https://hibernate.atlassian.net/browse/HHH-18559 upstream, let's see how that goes. |
Thanks for you effort 👌😊 |
So. HHH-18559 was deemed "not a bug" as it seems in this particular case, auto-flush was not designed to help. Hence, this is unlikely to get fixed in Hibernate ORM 6.6 and Quarkus 3.13/3.14/3.15. Now, there is still hope, since the Hibernate team is discussing HHH-18563 and may end up implementing it in a future version of Hibernate ORM, assuming there are no major downsides. In the meantime, I will close this, as it's not -- technically -- a bug: the previous behavior was unintended. Reminder of workarounds for anyone ending up here:
// Put this in an `@ApplicationScoped` bean somewhere.
void onBeginTransaction(@Observes @Initialized(TransactionScoped.class) Object event, Session session) {
session.setHibernateFlushMode(FlushMode.ALWAYS);
} |
Thanks for the hints @yrodiere ! I also have some issues with the new flush mode, so I tried to revert to the old behavior but I have exatly the same issues, so I imagine it didn't change the way the sessions are flushed. Here is my code: @ApplicationScoped
class HibernateFlushModeConfig {
fun onBeginTransaction(@Observes @Initialized(TransactionScoped::class) event: Any, session: Session) {
session.hibernateFlushMode = FlushMode.ALWAYS
}
} |
@cthiebault Right, I didn't test this, just provided the workaround to someone else a while ago and got no answer, so I assumed there was no problem... maybe there is. My first suspicion would be Kotlin, but if you checked that the bean indeed gets executed... there's probably a timing issue. Debugging You can probably try something like this? quarkus.hibernate-orm.unsupported-properties."org.hibernate.flushMode"=ALWAYS |
Debugging
But even with this, I get some |
Then this is probably a different problem... possibly one in Hibernate ORM... and we'll need a reproducer and report. Ideally directly in Hibernate ORM 's Jira instance if you manage to write a reproducer based on https://github.com/hibernate/hibernate-test-case-templates/blob/main/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/QuarkusLikeORMUnitTestCase.java. Thanks in advance :) |
Describe the bug
Since 3.13.0 a panache update statement fails under certain conditions.
When detaching an entity, changing its primary key and persist it as duplicate without flushing , then updating the foreign key in another entity, the update statement fails as the session seems not to know the new id.
Calling an explicit flush after persists seems to workaround the problem.
This is a change of behavior from 3.12.3 to 3.13.0
This issue is related with the history of changes of #42400
Expected behavior
No change of behavior. All tests of the reproducer should pass using Quarkus 3.13.x
How to Reproduce?
https://github.com/HerrDerb/quarkus-issue/tree/panache-entitymanager-session-issue
Run tests with 3.13.x -> one will fail
Run tests with 3.12.3 -> all pass
The text was updated successfully, but these errors were encountered: