atomikos / transactions-essentials

Development repository for next major release of
https://www.atomikos.com/Main/TransactionsEssentials
Other
461 stars 139 forks source link

Atomikos, JaVers, and Hibernate #192

Open ghost opened 1 year ago

ghost commented 1 year ago

Hi all

I am having an issue getting the latest versions of Atomikos, JaVers, and Hibernate to work together on a Spring Boot 3 project. After some debugging, I have managed to narrow the issue down to the fact that JaVers is receiving an already closed connection from the entity manager, which is then throwing a SQL exception. The code that JaVers uses to get a connection is as follows:

public Connection getConnection() {
  Session session = (Session)this.entityManager.unwrap(Session.class);
  GetConnectionWork connectionWork = new GetConnectionWork();
  session.doWork(connectionWork);
  return connectionWork.theConnection;
}

After which it performs its inserts into the audit tables using that connection. This all works out of the box using native JPA and Hibernate, however as soon as I add in the Atomikos dependency to make the application transactional, the connection being returned is already closed.

Looking at the Hibernate documentation and suggestions, it is my understanding that the recommended way to perform work on a session is to pass it in to the doWork() and doReturningWork() methods rather than using the connection directly. Unfortunately, this is not the way that JaVers works.

So my question is, if I create a custom ConnectionProvider, is there any way I can get an open connection from the entity manager's session while using Atomikos/JTA?

Any help or suggestions would be greatly appreciated.