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

JPA concurrent locking of Entities fails in Quarkus 3.0.0.CR2 #32532

Closed
mensinda opened this issue Apr 11, 2023 · 2 comments · Fixed by #36978
Closed

JPA concurrent locking of Entities fails in Quarkus 3.0.0.CR2 #32532

mensinda opened this issue Apr 11, 2023 · 2 comments · Fixed by #36978
Assignees
Labels
area/hibernate-orm Hibernate ORM kind/bug Something isn't working
Milestone

Comments

@mensinda
Copy link

Describe the bug

If I concurrently lock (PESSIMISTIC_WRITE) and modify an Entity with a @Version field, quarkus / hibernate throws a StaleObjectStateException. The relevant example code can be found here. This used to work in Quarkus 2.x.

This can be circumvented by directly locking the Entity with the find call.

I am not sure if this is a Quarkus or Hibernate bug, but I decided to ask here first just in case.

Expected behavior

Tests pass

Actual behavior

Tests fail

jakarta.persistence.OptimisticLockException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [root.TestEntity#42]
	at org.hibernate.internal.ExceptionConverterImpl.wrapStaleStateException(ExceptionConverterImpl.java:204)
	at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:93)
	at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
	at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:168)
	at org.hibernate.internal.SessionImpl.fireRefresh(SessionImpl.java:1306)
	at org.hibernate.internal.SessionImpl.refresh(SessionImpl.java:1272)
	at org.hibernate.internal.SessionImpl.refresh(SessionImpl.java:1266)
	at org.hibernate.internal.SessionImpl.refresh(SessionImpl.java:2583)
	at org.hibernate.internal.SessionImpl.refresh(SessionImpl.java:2562)
	at io.quarkus.hibernate.orm.runtime.session.TransactionScopedSession.refresh(TransactionScopedSession.java:303)
	at org.hibernate.engine.spi.SessionLazyDelegator.refresh(SessionLazyDelegator.java:819)
	at org.hibernate.Session_3a974b6a18ac399f675913d732c105426414d370_Synthetic_ClientProxy.refresh(Unknown Source)
	at test.MTTest.mtLock(MTTest.java:93)
	at test.MTTest_Subclass.mtLock$$superforward(Unknown Source)
	at test.MTTest_Subclass$$function$$3.apply(Unknown Source)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:74)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:63)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:136)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:107)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.doIntercept(TransactionalInterceptorRequired.java:38)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:61)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:32)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:38)
	at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:26)
	at test.MTTest_Subclass.mtLock(Unknown Source)
	at test.MTTest.lambda$multithreading$0(MTTest.java:49)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [root.TestEntity#42]
	at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.checkVersion(AbstractEntityInitializer.java:577)
	at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.upgradeLockMode(AbstractEntityInitializer.java:545)
	at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.resolveEntityInstance(AbstractEntityInitializer.java:529)
	at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.resolveInstance(AbstractEntityInitializer.java:402)
	at org.hibernate.sql.results.internal.InitializersList.resolveInstances(InitializersList.java:88)
	at org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:110)
	at org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:87)
	at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:179)
	at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:33)
	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:362)
	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:168)
	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:93)
	at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31)
	at org.hibernate.loader.ast.internal.SingleIdLoadPlan.load(SingleIdLoadPlan.java:144)
	at org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl.load(SingleIdEntityLoaderStandardImpl.java:88)
	at org.hibernate.loader.ast.internal.SingleIdEntityLoaderDynamicBatch.load(SingleIdEntityLoaderDynamicBatch.java:76)
	at org.hibernate.persister.entity.AbstractEntityPersister.doLoad(AbstractEntityPersister.java:3370)
	at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3351)
	at org.hibernate.event.internal.DefaultRefreshEventListener.doRefresh(DefaultRefreshEventListener.java:214)
	at org.hibernate.event.internal.DefaultRefreshEventListener.lambda$refresh$0(DefaultRefreshEventListener.java:148)
	at org.hibernate.engine.spi.LoadQueryInfluencers.fromInternalFetchProfile(LoadQueryInfluencers.java:79)
	at org.hibernate.event.internal.DefaultRefreshEventListener.refresh(DefaultRefreshEventListener.java:146)
	at org.hibernate.event.internal.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:70)
	at org.hibernate.event.internal.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:50)
	at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
	at org.hibernate.internal.SessionImpl.fireRefresh(SessionImpl.java:1297)
	... 24 more

How to Reproduce?

To reproduce the error:

  1. Check out the mtLocking branch of this repository: https://github.com/mensinda/quarkus-stuff/tree/mtLocking
  2. run mvn clean verify

To see that it used to work in Quarkus 2.x:

  1. run ./downgrade.sh
  2. run mvn clean verify

Output of uname -a or ver

Linux 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.6" 2023-01-17

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.0.0.CR2

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

Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)

Additional information

No response

@mensinda mensinda added the kind/bug Something isn't working label Apr 11, 2023
@geoand geoand added area/hibernate-orm Hibernate ORM and removed triage/needs-triage labels Apr 11, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 11, 2023

/cc @Sanne (hibernate-orm), @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

@yrodiere yrodiere self-assigned this Apr 12, 2023
@yrodiere
Copy link
Member

Thanks for reporting. This is a regression in Hibernate ORM 6, tracked here: https://hibernate.atlassian.net/browse/HHH-16461

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants