This content has been marked as final.
Show 1 reply
-
1. Re: Hibernate - Unable to locate current JTA transaction
bmcgovern Oct 25, 2006 3:56 PM (in response to bmcgovern)I seemed to get around it with the following code.
But does anyone know if im on the right track here? Is openSession() worse than getCurrentSession()?Session hsession = null; try { InitialContext ctx = new InitialContext(); //UserTransaction tx = (UserTransaction)ctx.lookup("java:comp/UserTransaction"); //tx.begin(); SessionFactory factory = (SessionFactory) ctx.lookup("java:/teenfit/TeenFitDataSessionFactory"); hsession = factory.openSession(); // Session hsession = // TeenFitHibernateUtil.getSessionFactory().getCurrentSession(); // zTransaction = (Transaction)new // InitialContext().lookup("java:comp/UserTransaction"); //Transaction t = hsession.getTransaction(); // System.out.println("**TRANSACTION FOUND**:: tx = " + tx.toString()); System.out.println("**TRANSACTION FOUND**:: session = " + hsession.getTransaction().toString()); hsession.getTransaction().begin(); hsession.saveOrUpdate(HibernateTFUser); hsession.saveOrUpdate(HibernateTFUser2); hsession.getTransaction().commit(); //tx.commit(); }catch (Exception zEX){ System.out.println("Eception:" + zEX.toString()); hsession.getTransaction().rollback(); }