-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Current transaction is not in progress
PostPosted: Fri Aug 18, 2006 2:43 pm 
Beginner
Beginner

Joined: Tue Aug 08, 2006 11:53 am
Posts: 37
Hi all,

I am using the JTA as explained in the hibernate documentation. The documentation says that if there is no transaction currently started, a new transaction will be opened upon the call to "getCurrentSession" method. however, when i call the following method "createCsa", it is throwing "Current transaction is not in progress" exception under WAS 6.

I'd appreciate if someone help me resolve this!

Hibernate version: 3.x

Code between sessionFactory.openSession() and session.close():

public Long createCsa(Csa csa) {
Session session = DAOFactory.getCsaSessionFactory().getCurrentSession();
Transaction tx=null;
Long id=null;

try {
tx = session.beginTransaction();

id=(Long)session.save(csa);

tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
System.out.println(e);
}
return id;
}

Full stack trace of any exception that occurs:

[8/18/06 13:33:11:549 CDT] 00000043 WebApp E SRVE0026E: [Servlet Error]-[action]: 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:508)
at cat.dds.csm.dao.CsaDAOImpl.createCsa(CsaDAOImpl.java:23)
at com.aravind.struts.action.LiteFormUserRegistrationAction.execute(LiteFormUserRegistrationAction.java:97)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java(Compiled Code))
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2905)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)
at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))

Name and version of the database you are using: Oracle 10g


Top
 Profile  
 
 Post subject: FYI
PostPosted: Fri Aug 18, 2006 3:31 pm 
Beginner
Beginner

Joined: Tue Aug 08, 2006 11:53 am
Posts: 37
I guess the issues is that i am trying to open a current seesion before the begin of the transaction. I resolved this issues by demarcating the transactions in the session facade than in the DAO.

My new changed code looks like this

public Long createCsa(Csa csa) {
Session session = DAOFactory.getCsaSessionFactory().getCurrentSession();

Long id=null;

try {

id=(Long)session.save(csa);

}
catch (Exception e) {
//if (tx!=null) tx.rollback();
//System.out.println(e);
}
return id;
}

and the code in session facade looks lie this

Transaction tx=DAOFactory.getCsaSessionFactory().openSession().beginTransaction();

//call methods on various DAOs which constitue one logical unit fo work

tx.commit();

//tx.rollback() in case of exceptions


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 19, 2006 7:00 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
The JTA Current Session context works best when called within the scope a transactional component such as an EJB or an explicit look up to a UserTransaction. If called with in an EJB, you do not need to call session.beginTransaction() and this is redundant. However, I have to a gree with you the the Hibernate docs do imply that calling session.beginTransaction() would create a new JTA transaction. I have found this is indeed not the case in both WebLogic and JBoss. Now I'll add WAS to the list ;)

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
 Post subject: Current transaction is not in progress
PostPosted: Tue Dec 11, 2007 6:27 am 
Newbie

Joined: Fri Dec 07, 2007 9:25 am
Posts: 5
Hi,

I am new to Hibernate. Working in EJB-CMT with WAS 6.0
I faced the following exception while working the NotSupported transaction call from SessionEJB

[12/11/07 16:04:17:933 IST] 00000031 ExceptionUtil E CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "synchronize" on bean "BeanId(MUISEJBEAR#MUISPROCESSEJB.jar#SynchronizerProcessEJB, null)". Exception data: 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)
at com.visiontss.muis.model.util.HibernateUtil.currentSession(HibernateUtil.java:69)
at com.visiontss.muis.dao.DataAccessObject.executeHQL(DataAccessObject.java:507)


Given below is my hibernate.cfg.xml

<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.CMTTransactionFactory
</property>
<property name="hibernate.transaction.manager_lookup_class">
org.hibernate.transaction.WebSphereExtendedJTATransactionLookup
</property>
<property name="hibernate.transaction.flush_before_completion">
true
</property>
<property name="hibernate.transaction.auto_close_session">
true
</property>

<property name="hibernate.current_session_context_class">
jta
</property>


Any help is appreciated

Thanks in advance,
Raji.T


Top
 Profile  
 
 Post subject: Current transaction is not in progress
PostPosted: Tue Dec 11, 2007 12:25 pm 
Newbie

Joined: Fri Dec 07, 2007 9:25 am
Posts: 5
Hi all,

The problem which I posted is resolved.
In session bean we should not use NotSupported as transaction attribute.
Have to use Required or RequiredNew.


Once I changed the transaction attribute it is working fine.

Regards,
Raji.T


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 6:14 pm 
Newbie

Joined: Mon Oct 06, 2008 1:25 pm
Posts: 1
When you change it required or requiresNew, that means the Container must manage it-------OVERHEAD. If you have a transaction which is only read only db hits, you should use <trans-attribute>notSupported</trans-attribute>.

anyone figure out how to actually use NotSupported with hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 12:54 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.