Skip to content

HHH-17743 Allow updates outside transaction #7867

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

Merged
merged 1 commit into from
Mar 15, 2024
Merged

Conversation

@beikov
Copy link
Member

beikov commented Feb 20, 2024

Please also add a test that reproduces the problem to the test class org.hibernate.orm.test.flush.NonTransactionalDataAccessTest.

@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Feb 21, 2024

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@subijayb
Copy link
Author

Hi @beikov , could you please review the test case ?
I don't know why I cannot assign a reviewer

@beikov
Copy link
Member

beikov commented Feb 22, 2024

Please rebase and squash to a single commit

@subijayb
Copy link
Author

Hi @beikov, could you please check now and let me know the next step

@subijayb
Copy link
Author

Hi @beikov , could you please review and let me know the next steps?

@miles-po
Copy link

Hi @beikov. This is a showstopper bug when working with the latest version of Spring Boot and JPA.

@sebersole
Copy link
Member

Doing things outside a transation is never a show stopper ;)

Also, why is this targetting 6.4 and not main? Does this not happen on main?

@subijayb
Copy link
Author

subijayb commented Mar 15, 2024

Hi @sebersole ,

This bug impacts all 6.x branch. I pushed it to 6.4 hoping that 6.4.5 will come out soon and we can use this. I will also merge it to main branch.
Could you please review and merge this change?

@miles-po
Copy link

miles-po commented Mar 15, 2024

@sebersole Yes, my comment was intentionally provocative due to lack of response on what looks like a viable patch for three weeks. For reference, this shows up even when trying to execute queries from the EntityManager, even native queries. With or without @Transactional. The default deleteById works, but any other deleteBy variant hits this code path. em.getTransaction() doesn't work either because it's a managed em. It appears like our only option is to completely bypass the ORM and make queries on a raw DataSource. That option is unappealing considering a very simple patch already exists here upstream.

@beikov
Copy link
Member

beikov commented Mar 15, 2024

Sorry this takes so long, but please understand that the ORM team has it's own priorities and is not that huge to respond to every request so fast. We're all trying our best, but if you need guaranteed fast response times, consider becoming a Red Hat customer and create support tickets, because such tasks have priority over everything else that we do.

@miles-po
Copy link

Understood. Thank you for your efforts.

@beikov beikov merged commit 1d89c31 into hibernate:6.4 Mar 15, 2024
@subijayb
Copy link
Author

Thanks @beikov for merging. Could you please let know how to push it to main branch? I have to raise a new PR?

@sebersole
Copy link
Member

2 PRs is fine. Or (future) send a PR against main and we will port it to maintained branches generally

@dreab8
Copy link
Member

dreab8 commented Mar 16, 2024

@beikov
instead of removing
getSession().prepareForQueryExecution(true)

should not be something like
getSession().prepareForQueryExecution(false)

or

getSession().prepareForQueryExecution(
				requiresTxn( getQueryOptions().getLockOptions().findGreatestLockMode() ) )

@beikov
Copy link
Member

beikov commented Mar 18, 2024

I already merged it on main.

@dreab8 the change of this PR is fine IMO, because doExecuteUpdate() is only ever called from executeUpdate() which already does the following:

getSession().checkTransactionNeededForUpdateOperation( "Executing an update/delete query" );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants