I get a org.jooq.exception.DataAccessException in Java with a message
ERROR: could not serialize access due to read/write dependencies among transactions Detail: Reason code: Canceled on identification as a pivot, during conflict in checking. Hint: The transaction might succeed if retried.
I want to check the error code for the data access exception, which is a Postgres database behind the scene. For example, serialization failure exception error code is 40001.
How can i check the error code for the org.jooq.exception.DataAccessException?
My motive is to retry transaction if it's serialization failure.
In jOOQ 3.8, SQLStateClass and SQLStateSubclass were introduced (#4904) to give you type safe access to the SQL standard SQL state values.
catch (DataAccessException e) {
System.out.println(e.sqlStateClass());
System.out.println(e.sqlStateSubclass());
if (SQLStateSubclass.C40001_SERIALIZATION_FAILURE == e.sqlStateSubclass()) {
...
}
}
Prior to jOOQ 3.8, you can access the underlying SQLException in order to access these SQL state values:
catch (DataAccessException e) {
if (e.getCause() instanceof SQLException &&
("40001".equals(((SQLException) e.getCause()).getSQLState()))) {
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With