it seems that we found a possible problem source: session.connection(). If we call session.connection() and after that do trx rollback, it leads to our XAER_PROTO problem.
In the Hibernate documentation is stated that one has to do connection.rollback/commit, when using session.connection(). But in case of XA transactions it's not allowed resulting in: Cannot call rollback when using distributed transactions.
So it seems that we can't do anything with the connection. The only thing we do is trx.rollback() and session.close().
What is the right way to deal with plain JDBC connections obtained from the Hibernate Session?
All above works assuming that the following is configured in the hibernate config xml:
Code:
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="hibernate.transaction.auto_close_session">true</property>