Join GitHub today
Postgres foreign_key_violation not correctly mapped to XAException #1171
We have a database schema with several deferrable constraints. This means that constraints violations are noticed when the transaction is committed and not when the statement itself is executed. We are using the Atomikos distributed transaction manager as well.
Recently we noticed that a foreign_key_violation error from the server during the commit resulted in the transaction not being cleaned up in Atomikos. Further investigation revealed that:
In our opinion it would be better to map SQLState "23503" to an XAException with error code XA_RBROLLBACK. Doing so would result in the correct behaviour.
We are using PostgreSQL 9.6.6 with JDBC driver version 42.2.2 and Atomikos transactions-essentials 4.0.6. You can find the (redacted) stacktrace in attachment.