I was finally able to isolate my problem, which seems to be related to native inserts/updates.
The following code works with Hibernate 4.3.11, but fails with TransactionRequiredException on Hibernate 5.2.12:
Code:
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test");
SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
Session ses = sessionFactory.openSession();
Transaction tx = ses.beginTransaction();
ses.doReturningWork(new ReturningWork<Void>() {
@Override
public Void execute(Connection connection) throws SQLException {
StatelessSession sls = sessionFactory.openStatelessSession(connection);
SQLQuery q = sls.createSQLQuery("INSERT INTO testentity (id) values(1)");
q.executeUpdate();
return null;
}
});
Is this a bug, or just a wrong way to use Hibernate?