-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
I was trying test transaction retry as per https://www.cockroachlabs.com/docs/v22.2/build-a-java-app-with-cockroachdb-hibernate?filters=local but it looks like the example is not working any more.
I am changing the flag private static final boolean FORCE_RETRY = true;
and running ./gradlew run
:
Exception in thread "main" javax.persistence.OptimisticLockException: org.hibernate.exception.LockAcquisitionException: could not execute statement
at org.hibernate.internal.ExceptionConverterImpl.wrapLockException(ExceptionConverterImpl.java:277)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:98)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1621)
at com.cockroachlabs.Sample.lambda$forceRetryLogic$2(Sample.java:106)
at com.cockroachlabs.Sample.runTransaction(Sample.java:161)
at com.cockroachlabs.Sample.main(Sample.java:209)
Caused by: org.hibernate.exception.LockAcquisitionException: could not execute statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:120)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200)
at org.hibernate.engine.query.spi.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:107)
at org.hibernate.internal.SessionImpl.executeNativeUpdate(SessionImpl.java:1509)
at org.hibernate.query.internal.NativeQueryImpl.doExecuteUpdate(NativeQueryImpl.java:295)
at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1612)
... 3 more
Caused by: org.postgresql.util.PSQLException: ERROR: restart transaction: crdb_internal.force_retry(): TransactionRetryWithProtoRefreshError: forced by crdb_internal.force_retry()
Hint: See: https://www.cockroachlabs.com/docs/v20.2/transaction-retry-error-reference.html
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:130)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)
Looks like changing
catch (JDBCException e) {
in runTransaction
to:
} catch (PersistenceException pe) {
JDBCException e;
if (pe instanceof JDBCException) {
e = (JDBCException) pe;
} else if (pe.getCause() instanceof JDBCException) {
e = (JDBCException) pe.getCause();
} else {
throw pe;
}
and in JDBCException
to PersistenceException
in another method seem to fix the problem.
Metadata
Metadata
Assignees
Labels
No labels