Calling flush before query execution may cause PropertyValueException: Detached entity with generated id
Description
The issue may be related to
I’ve got the following exception in multiple cases:
However flush method should be called before query execution in all cases. Also, ID is autogenerated and not manually set
The following cases cause the error:
Call flush and clean before executing a select query with one-to-one relations.
Call flush and detach entities before executing a select query with one-to-one relations.
Call flush multiple times in different transactions
There are more cases when this error may occur. However, I think the root cause of the issue is the same. therefore, it should be enough information to fix this issue in all cases.
I’ve attached a reproducer. Please run tests inside org.hibernate.bugs.JPAUnitTestCase
Attachments
1
Activity
Show:
Ruslan Gryn last week
bad news. Do you have any insights into which task this issue might have been addressed in the main branch?
Marco Belladelli last week
I don’t see how the two issues are related. I’ve tested your reproducer with the latest 6.6.14-SNAPSHOT, which includes the fix for , and the issue persists in all cases.
Gavin King last week
That sounds quite surprising and borderline suspicious.
Ruslan Gryn last week
Edited
It looks like that you fixed this issue in the scope of
Can you confirm it using my reproducer?
Ruslan Gryn April 9, 2025 at 11:22 AM
thanks. I will try to back-port the changes from H 7
The issue may be related to
I’ve got the following exception in multiple cases:
However
flush
method should be called before query execution in all cases. Also, ID is autogenerated and not manually setThe following cases cause the error:
Call
flush
andclean
before executing a select query with one-to-one relations.Call
flush
anddetach
entities before executing a select query with one-to-one relations.Call
flush
multiple times in different transactionsThere are more cases when this error may occur. However, I think the root cause of the issue is the same. therefore, it should be enough information to fix this issue in all cases.
I’ve attached a reproducer. Please run tests inside
org.hibernate.bugs.JPAUnitTestCase