1

I have some model objects that are Hibernate entities, and others that cannot be (because I don't own the code). I need transactions that span updates to both objects. Basically, I want to do this:

Transaction txn = sessionFactory.getCurrentSession().beginTransaction();
fooDao.update(...); // Hibernate-based DAO

// (Apparently the way to get the JDBC Connection.)
Connection con = sessionFactory.
    getSessionFactoryOptions().getServiceRegistry().
    getService(ConnectionProvider.class).getConnection();

try (var ps = con.prepareStatement(...)) {
    ps.setString(...);
    ps.executeUpdate();
}

txn.commit();

In JDBC, starting a transaction is nothing more than setting autoCommit=false on the connection (AFAICT). I don't know exactly what Hibernate does to start a transaction. Will there be any problem mixing the two kinds of updates like this?

A_P
  • 326
  • 1
  • 12
  • Does this answer your question? [How to configure Spring to make JPA (Hibernate) and JDBC (JdbcTemplate or MyBatis) share the same transaction](https://stackoverflow.com/questions/6777419/how-to-configure-spring-to-make-jpa-hibernate-and-jdbc-jdbctemplate-or-mybati) – crizzis Aug 31 '20 at 17:31
  • @crizzis I don't think so. That question uses Spring, which I don't use. – A_P Aug 31 '20 at 17:51

0 Answers0