As far as I know Hibernate does call session.flush() before committing. But, in order to allow this behavior, you have to make sure that it's aware of the underlying transaction handling. In hibernate.properties you find a section called "Transaction API" where you should set: 1- the transaction factory class hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory
2- the JNDI address for the UserTransaction (unless the default java:comp/UserTransaction comply with your environment) Usually you don't pass a connection in openSession() while relying on JTA so that it open and close the connection when needed. Since the forum has started we see such user questions there instead of the dev list. That's why before I replied you without cc the list. However let me say again that pdf doc, javadoc and several pages in the site explain this topic far better than me. good luck stefano -----Messaggio originale----- Da: dosapati [mailto:[EMAIL PROTECTED] Inviato: giovedì 25 settembre 2003 12.48 A: Travelli Stefano; [EMAIL PROTECTED] Oggetto: Re: [Hibernate] problem in using JTA datasources Stefano, thanks for your response. Yes, it is working now. But I have a major doubt on session.flush(). It was working without session.flush() when I begin the transaction with session.beginTransaction() and not setting external connection. When JTA UserTransaction is handled by application and external connection is set to the session, why session.flush() is required before committing? Cant session itself flush when JTA transaction is committed. Please clarify this difference. I would like to not use session.flush() in my code. Thanks for your suggessions. dosapati ----- Original Message ----- From: "Travelli Stefano" <[EMAIL PROTECTED]> To: "dosapati" <[EMAIL PROTECTED]> Sent: Thursday, September 25, 2003 3:06 PM Subject: R: [Hibernate] problem in using JTA datasources > Change the order of the last statements: > > // first flush the session > session.flush(); > // then close the session > session.close(); > // close the connection > cn.close(); > // and finally commit > ut.commit(); > > However you need better exception handling. Hibernate works great with JTA. > > I suggest you to read best practices in the web site. > > Hope this helps. > > stefano > > -----Messaggio originale----- > Da: dosapati [mailto:[EMAIL PROTECTED] > Inviato: giovedì 25 settembre 2003 9.46 > A: [EMAIL PROTECTED] > Oggetto: [Hibernate] problem in using JTA datasources > > > I am facing problems in using UserTransaction & JTA datasource with Hibernate. > > I am using JOTM as TransactionManager and XAPool ass JTA datasource. To use them, > first I resitered them from Tomcat's server.xml as Resources. > > My java code is like this: > > try { > Context ctx = new InitialContext(); > ut = (UserTransaction)ctx.lookup("java:comp/UserTransaction"); > ut.begin(); > javax.sql.DataSource myDataSource = (javax.sql.DataSource) ctx.lookup("java:comp/env/MyDataSource"); > myConn = myDataSource.getConnection(); > session = sessionFactory.openSession(myConn); > > Cat princess = new Cat(); > princess.setName("Princess"); > princess.setSex('F'); > princess.setWeight(7.4f); > session.save(princess); > session.save(princess); > > System.out.println("committing Transaction..."); > ut.commit(); > myConn.close(); > session.close(); > }catch(Exception ex) { > System.out.println("rollingback Transaction..."); > ut.rollback(); > } > > > The first print statement 'committing Transaction.....' is getting printed when I execute > the above code. But the changes are not getting updated in database. > > This is working when I start Transaction from session.beginTransaction() and not setting the > external connection to the Session object. > > What was the wrong with my code?. I could not find any example code or any post on using JTA > Transaction Manager and JTA datasource with Hibernate. Any suggessions are appreciated. > > Thanks in advance! > Dosapati ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel