Here my configuration:
Code:
<!-- Enable Hibernate's automatic session context management -->
<property name="hibernate.current_session_context_class">jta</property>
<!-- Transaction API -->
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property >
I am trying to configure 'jta' with Websphere 6.0 app server. But I receive the exception:
Code:
org.hibernate.HibernateException: Current transaction is not in progress
at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:67)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
I am not using EJB. Data layer classes(DAOs) access hibernate. Here is the code that access hibernate session:
Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = null;
boolean existingTransaction = false;
try {
tx = session.getTransaction();
existingTransaction = (tx != null && tx.isActive());
if (existingTransaction) {
log.debug("Found thread-bound Session");
}else{
tx.begin();
}
Object result = action.doInHibernate(session);
if(!existingTransaction && tx != null && tx.isActive() &&
!tx.wasCommitted() && !tx.wasRolledBack())
tx.commit();
else
session.flush();
return result;
}
catch (HibernateException ex) {
if(!existingTransaction && tx != null && tx.isActive() &&
!tx.wasCommitted() && !tx.wasRolledBack()){
try{
tx.rollback();
}catch(HibernateException ex2){
throw convertHibernateException(ex2);
}
}
throw convertHibernateException(ex);
}
catch (SQLException ex) {
throw convertSQLException(ex);
}
catch (RuntimeException ex) {
log.error("RuntimeException: "+ex.getCause());
// Callback code threw application exception...
throw new TechnicalException(CLASS_NAME, ex.getMessage(), ex);
}
finally {
if (existingTransaction) {
//In case of existing transcation, session should be closed from the
//place it is opened first time.
log.debug("Not closing pre-bound Hibernate Session");
}
else {
HibernateUtil.getSessionFactory().getCurrentSession().close();
}
}//try-catch-finally
Please let me know what I am missing if you have configured 'jta' with Websphere 6.0 successfully.