Atomikos Forum

Hibernate Transaction API not working

Hi. I have a configuration consisting of TransactionEssentials 3.3.1 + Tomcat 5.5.26 + Hibernate 2.1.7 + PostgreSQL 8.2.5. These are the relevant config fragments.

hibernate.cfg.xml:

<property name="connection.datasource">java:comp/env/jdbc/myDB</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate.TransactionManagerLookup</property>

appContext.xml (I use a modified version of BeanFactory available at http://www.atomikos.com/Documentation/Tomcat55Integration33, since xaProperties expects a java.util.Properties object, not a String):

<Resource name="jdbc/myDB" auth="Container"
      type="com.atomikos.jdbc.AtomikosDataSourceBean"
      factory="my.atomikos.tomcat.BeanFactory"
      uniqueResourceName="jdbc/myDB"
      xaDataSourceClassName="org.postgresql.xa.PGXADataSource"
      maxPoolSize="100"
      minPoolSize="10"
      xaProperties="user=test;password=test;serverName=localhost;portNumber=5432;databaseName=myDB"/>

jta.properties:

com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
com.atomikos.icatch.log_base_dir=../work
com.atomikos.icatch.output_dir=../work
com.atomikos.icatch.console_log_level=DEBUG
com.atomikos.icatch.max_timeout=2147483647

I have also modified Tomcat's conf/server.xml and conf/context.xml, as explained at http://www.atomikos.com/Documentation/Tomcat55Integration33.

The problem is that wasCommitted() and wasRolledback() methods of Hibernate Transaction API don't work:

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
try {
    Test test = new Test();
    test.setTest("test");
    session.save("test");
    tx.commit();
    System.out.println(tx.wasCommitted()); // false????
} catch (Exception e) {
    tx.rollback();
    e.printStackTrace();
} finally {
    session.close();
    sessionFactory.close();
}

In the previous code, right after tx.commit(), tx.wasCommitted() returns false. I've seen that Atomikos removes the transaction data as soon as is committed, so when net.sf.hibernate.transaction.JTATransaction asks for the status of the underlying UserTransaction, it gets Status.STATUS_NO_TRANSACTION and thus it returns false.

This is breaking my code, it's an expected behaviour?

Thanks in advance
Diego Send private email
Monday, June 09, 2008
 
 
Hi,

Were you using a transaction manager before trying Atomikos ?

According to the JTA spec, calling UserTransaction.getStatus() must return STATUS_NO_TRANSACTION after commit or rollback happened so I'd say Hibernate is wrong here.

I'd suggest you stop using the Hibernate transaction API and use the JTA one directly instead.
Ludovic Orban Send private email
Monday, June 09, 2008
 
 
Hi, Ludovic, thanks for your reply.

I'll post this on the Hibernate forums.

So, what are Transaction.STATUS_COMMITTED and Transaction.STATUS_ROLLEDBACK used for?

Regards,
Diego
Diego Send private email
Monday, June 09, 2008
 
 
Forgot to add: no, I wasn't using a transaction manager before, I was using Hibernate transaction API with simple JDBC transactions. That's why I need to keep using this API, it's all over the code.
Diego Send private email
Monday, June 09, 2008
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics