I want to use a outer hibernate transaction and an inner jdbc transaction as below. I am new to Hibernate and i want to know, will nesting of transactions pose any issue even if it works.
Transaction transaction = session.beginTransaction(); SessionFactory sessionFactory = configuration.buildSessionFactory(); Session session = sessionFactory.openSession(new LoggerInterceptor()); Transaction transaction = null; Connection con =null;
try{ transaction = session.beginTransaction(); session.save(obj1); session.save(obj2); // Session session1 = sessionFactory.openSession(); con = session1.getConnection(); //Needed to start a new transaction to be used in legacy code con.setAutoCommit(false); //Do db operations
if(transaction.isActive()){ con.commit(); transaction.commit();
} }catch(Exception e1){ session.clear(); transaction.rollback(); } //clean -up code .....
Thanks in advance, Naveen
|