Skip to content
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

@OptimisticLocking(DIRTY) leads to wrong query during delete of circular reference #24842

Closed
mickroll opened this issue Apr 8, 2022 · 10 comments · Fixed by #26625
Closed

@OptimisticLocking(DIRTY) leads to wrong query during delete of circular reference #24842

mickroll opened this issue Apr 8, 2022 · 10 comments · Fixed by #26625
Labels
area/hibernate-orm Hibernate ORM env/windows Impacts Windows machines kind/bug Something isn't working triage/upstream Used for issues which are caused by issues in upstream projects/dependency
Milestone

Comments

@mickroll
Copy link
Contributor

mickroll commented Apr 8, 2022

Describe the bug

Having a circular reference between two Entities and deleting one of them with cascading enabled, the final delete query fails, if the "root"-Entity uses @OptimisticLocking(DIRTY).

Expected behavior

The following queries are generated and executed:

update `example_entity` set `last_log_entry_id`=null where `id`=?
delete from `log_entry` where `id`=?
delete from `example_entity` where `id`=? and `last_log_entry_id` IS NULL

All query-parameters are filled with non-null, existing values.
Both deletes are successful.

Actual behavior

The following queries are generated and executed:

update `example_entity` set `last_log_entry_id`=null where `id`=?
delete from `log_entry` where `id`=?
delete from `example_entity` where `id`=? and `last_log_entry_id`=?

All query-parameters are filled with non-null, existing values.
The last query is wrong and references old state that was changed in the first query.
This leads to the following error:

javax.persistence.OptimisticLockException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

How to Reproduce?

see https://github.com/mickroll/quarkus-demonstrator/tree/optimistic-locking-circular-reference-delete
Demonstrator uses Quarkus 2.6.2.Final, but the same Bug also appears on Quarkus 2.8.0.Final.

Output of uname -a or ver

Windows 10

Output of java -version

openjdk version "11.0.12"

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.6.2.Final / 2.8.0.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.6.3

Additional information

No response

@mickroll mickroll added the kind/bug Something isn't working label Apr 8, 2022
@quarkus-bot quarkus-bot bot added env/windows Impacts Windows machines triage/needs-triage labels Apr 8, 2022
@famod famod added area/hibernate-orm Hibernate ORM and removed triage/needs-triage labels Apr 8, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 8, 2022

/cc @Sanne, @gsmet, @yrodiere

@Sanne
Copy link
Member

Sanne commented Apr 11, 2022

hi @mickroll - thanks for the report. May I assume I can ask the Hibernate ORM team to have a look, or is there a specific reason to have reported it to Quarkus?

@mickroll
Copy link
Contributor Author

mickroll commented Apr 11, 2022

Now that you are asking, yes this is hibernate-related. Please feel free to forward.

@famod
Copy link
Member

famod commented Apr 14, 2022

Hey @Sanne, is there a HHH issue already?

@mickroll
Copy link
Contributor Author

FYI @Sanne i just reported this as a hibernate issue: https://hibernate.atlassian.net/browse/HHH-15218

@famod famod added the triage/upstream Used for issues which are caused by issues in upstream projects/dependency label Apr 20, 2022
@famod
Copy link
Member

famod commented Jul 4, 2022

Hi @Sanne @yrodiere, any chance to fix this upstream? 🙂

@Sanne
Copy link
Member

Sanne commented Jul 4, 2022

sorry for the lack of communications.

I've pinged the ORM team to make sure it gets triaged, seems to have fallen through the cracks. Not sure if we'll have the bandwith to fix it in 5, but let's see what the team thinks.

@Sanne
Copy link
Member

Sanne commented Jul 8, 2022

this was fixed by @dreab8 in Hibernate ORM, so we'll have a fix when merging #26625

@famod
Copy link
Member

famod commented Jul 8, 2022

Awesome, thanks @dreab8 & @Sanne!

@mickroll
Copy link
Contributor Author

this was fixed by @dreab8 in Hibernate ORM, so we'll have a fix when merging #26625

Sounds great 🚀

@quarkus-bot quarkus-bot bot added this to the 2.11 - main milestone Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM env/windows Impacts Windows machines kind/bug Something isn't working triage/upstream Used for issues which are caused by issues in upstream projects/dependency
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants