I use 4.3.11 in my Liberty projects but there is a bug with Hibernate solved in version 5. I have tried upgrading but I get different exceptions.
Anybody is using Hibern
I've been able to get Hibernate 5.x at least partially working in Liberty if I include these JARs:
The reason I say partially working is that it works great if using non-jta-data-source, but when trying to use jta-data-source, Hibernate can fail trying to locate vendor-specific API to suspend the current transaction. Hibernate does have some properties that you can set to tell it that it's being used by WebSphere servers, and I've explored various combinations of those without a successful outcome for jta-data-source. I think the Hibernate implementation is lacking in its awareness of Liberty, which is something that really ought to be added, (see HHH-10388 and vote for it if you would find it valuable) although in its absence you can get it working by writing your own implementation of Hibernate JtaPlatform that delegates to com.ibm.tx.jta.TransactionManagerFactory and specifying it as a persistence property.
For example in persistence.xml,
org.hibernate.jpa.HibernatePersistenceProvider
...
Example implementation,
package example;
import com.ibm.tx.jta.TransactionManagerFactory;
import javax.naming.*;
import javax.transaction.*;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
public class WebSphereLibertyJtaPlatform implements JtaPlatform {
public boolean canRegisterSynchronization() {
try {
return getCurrentStatus() == Status.STATUS_ACTIVE;
} catch (SystemException x) {
throw new RuntimeException(x);
}
}
public int getCurrentStatus() throws SystemException {
return retrieveTransactionManager().getStatus();
}
public Object getTransactionIdentifier(Transaction transaction) {
return transaction;
}
public void registerSynchronization(Synchronization synchronization) {
try {
retrieveTransactionManager().getTransaction().registerSynchronization(synchronization);
} catch (IllegalStateException x) {
throw new RuntimeException(x);
} catch (RollbackException x) {
throw new RuntimeException(x);
} catch (SystemException x) {
throw new RuntimeException(x);
}
}
public TransactionManager retrieveTransactionManager() {
return TransactionManagerFactory.getTransactionManager();
}
public UserTransaction retrieveUserTransaction() {
try {
return InitialContext.doLookup("java:comp/UserTransaction");
} catch (NamingException x) {
throw new RuntimeException(x);
}
}
}