I have the following code to use Hibernate with JTA
Code:
UserTransaction utx = ServiceLocator.getInstance().getUserTransaction();
utx.begin();
Session session = sessionFactory.openSession();
session.save(new Employee("1", "Fred", "Flintstone");
utx.commit();
session.close();
The Hibernate configuration is as follows,
Code:
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.jdbc.batch_size">100</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.auto_import">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
<prop key="hibernate.query.substitutions">true=1,false=0</prop>
<prop key="hibernate.use_outer_join">true</prop>
<prop key="hibernate.max_fetch_depth">10</prop>
<prop key="hibernate.transaction.flush_before_completion">true</prop>
<prop key="hibernate.connection.release_mode">after_statement</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
<prop key="jta.UserTransaction">javax/transaction/UserTransaction</prop>
<prop key="hibernate.connection.datasource">dataSource</prop>
However, the object is not saved when the transaction is committed. The only way I can it working is to do an explicit flush. Is there anyway I can get Hibernate to automatically flush when the JTA transaction commits. I have been trying to use work arounds with transaction synchronization registration. I was wondering whether there was any simpler solution. I use Hibernate 3.0.
Any help would be highly appreciated.
Ta
Abu Mariam