[JIRA] (HHH-14110) "no transaction is in progress" when call entity manager find() with LockModeType
by Alex Popa-Tesileanu (JIRA)
Alex Popa-Tesileanu ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f1170d... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMmE4ZThlMzFm... ) / Improvement ( https://hibernate.atlassian.net/browse/HHH-14110?atlOrigin=eyJpIjoiMmE4ZT... ) HHH-14110 ( https://hibernate.atlassian.net/browse/HHH-14110?atlOrigin=eyJpIjoiMmE4ZT... ) "no transaction is in progress" when call entity manager find() with LockModeType ( https://hibernate.atlassian.net/browse/HHH-14110?atlOrigin=eyJpIjoiMmE4ZT... )
Issue Type: Improvement Affects Versions: 5.4.18 Assignee: Unassigned Components: hibernate-core Created: 17/Jul/2020 03:26 AM Environment: java 11,
hibernate 5.4.18,
JTA: narayana-jta-5.9.0,
SQL Server 2016
Windows 10
Labels: hibernate jta Priority: Major Reporter: Alex Popa-Tesileanu ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f1170d... )
When I use entity manager find() method with LockModeType inside JTA transaction boundaries, throw fowling exception:
_Exception in thread "main" javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:413)
at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:3395)
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3310)
at org.hibernate.internal.SessionImpl.find(SessionImpl.java:3292)
at ro.alsoco.tt.test.TestJPA.run(TestJPA.java:71)
at ro.alsoco.tt.test.TestJPA.main(TestJPA.java:24)
_
This doesn't happen when I use for example createQuery or if i call clear() or flush() before find().
After a few research I saw the majority of entity manipulation methods of EntityManager (SessionImpl or AbstractSharedSessionContract classes) execute on begining pulseTransactionCoordinator(). But find() mehod not.
I don't know if there are any special reason why find method not call pulseTransactionCoordinator(), witch I saw register synchronization with JTA.
For the moment I solved my problem issuing a joinTransaction() as first command after begin transaction.
Also, the problem doesn't happen if i create entity manager inside the JTA transaction. But I have strong resons to create entity manager outside the transaction.
It is possible to call pulseTransactionCoordinator() in find() method as bellow?
Maybe in next version?
_@Override
public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockModeType, Map<String, Object> properties) {
checkOpen();
pulseTransactionCoordinator();
.............
_
Thank you,
Alex
( https://hibernate.atlassian.net/browse/HHH-14110#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14110#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100133- sha1:d093d11 )