-->
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.  [ 5 posts ] 
Author Message
 Post subject: Bug in JTATransaction?
PostPosted: Sun Mar 26, 2006 3:23 pm 
Newbie

Joined: Tue Mar 21, 2006 1:42 pm
Posts: 14
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: Hibernate 3.1.2

Mapping documents: Not relevant

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

Code:
public void endActivityInstance(String user, int which, Collection results) throws UnavailableActivityInstanceException, InvalidResultsException {
        Session session = HibernateUtil.getSession();  //- thread local session
        Transaction xact = session.beginTransaction();

        try {
            updatePreviousUser(user, pf.getActivityInstance(which));
            endActivityInstance(which, results); //- method setResults (shown below) is in call path
            xact.commit();  //<<<----- EXCEPTION IS THROWN HERE
        }
        catch (Exception e) {
            xact.rollback();
            _LOG.warn("Could not commit transaction to end activity", e);
        }
}

protected final void setResults(ItemSet items) throws InvalidResultsException {
          Session session = HibernateUtil.getSession();
       Transaction xact = null;

       try {
           if (items == null) {
               throw new InvalidResultsException("Passed-in item set can not be null");               
           }
           
           xact = session.beginTransaction(); //- nested in the transaction started in endActivityInstance
           
           session.update(_items);
           session.update(this);
           
           xact.commit(xact);
           
        }
        catch (Exception e) {
             xact.rollback();
            throw new FailureException("Unable to save results of ActivityInstance #" + getWorkflowId(), e);
        }
    }


Full stack trace of any exception that occurs:

Code:
2006-03-23 00:13:20,078 ERROR [com.imsweb.seerdms.app.workflow.buslogic.WorkflowWebBean] Could not commit transaction to end activity; already finished
com.imsweb.seerdms.app.workflow.base.AlreadyFinishedException: org.hibernate.TransactionException: Transaction not successfully started
   at com.imsweb.seerdms.app.workflow.hibernate.HibernatePackageFactory.commit(HibernatePackageFactory.java:876)
   at com.imsweb.seerdms.app.workflow.buslogic.WorkflowWebBean.endActivityInstance(WorkflowWebBean.java:535)
   at com.imsweb.seerdms.app.workflow.buslogic.WorkflowWebSession.endActivityInstance(WorkflowWebSession.java:399)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
   at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
   at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
   at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:130)
   at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:51)
   at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
   at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:105)
   at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
   at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
   at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:139)
   at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
   at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
   at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
   at org.jboss.ejb.Container.invoke(Container.java:873)
   at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:413)
   at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:88)
   at $Proxy119.endActivityInstance(Unknown Source)
   at com.imsweb.seerdms.web.edit.record.DisplayRecordUtils.endScreeningActivity(DisplayRecordUtils.java:667)
   at com.imsweb.seerdms.web.edit.record.DisplayRecordAction.updateExit(DisplayRecordAction.java:933)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
   at com.imsweb.seerdms.web.shared.SeerAction.execute(SeerAction.java:118)
   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.doPost(ActionServlet.java:525)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
   at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.TransactionException: Transaction not successfully started
   at org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:126)
   at com.imsweb.seerdms.app.workflow.hibernate.HibernatePackageFactory.commit(HibernatePackageFactory.java:872)
   ... 57 more


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

The generated SQL (show_sql=true): Not relevant

Debug level Hibernate log excerpt:

In the code above, JTATransaction throws a TransactionException and probably shouldn't. The problem appears to be in the code below from JTATransaction:

Code:
   private void afterCommitRollback() throws TransactionException {
      
      begun = false;

      if (callback) { // this method is a noop if there is a Synchronization!

         if (!newTransaction) {
            log.warn("You should set hibernate.transaction.manager_lookup_class if cache is enabled");
         }
         int status=NULL;
         try {
            status = ut.getStatus();
         }
         catch (Exception e) {
            log.error("Could not determine transaction status after commit", e);
            throw new TransactionException("Could not determine transaction status after commit", e);
         }
         finally {
            /*if (status!=Status.STATUS_COMMITTED && status!=Status.STATUS_ROLLEDBACK) {
               log.warn("Transaction not complete - you should set hibernate.transaction.manager_lookup_class if cache is enabled");
               //throw exception??
            }*/
            jdbcContext.afterTransactionCompletion(status==Status.STATUS_COMMITTED, this);
         }

      }
   }


This method is called after the commit() method and the problematic line is "begun = false;". Begun is set to false after the commit of the nested transaction.
Then when the original transaction calls commit, it looks as if the transaction was never started because begun is set to false. I'm not sure where begun should be
reset at, but it probably shouldn't be here. I wanted to get others thoughts before posting this as a bug.

_________________
Mike Ringrose


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 6:50 pm 
Newbie

Joined: Tue Jul 05, 2005 11:47 pm
Posts: 15
Location: Argentina
I think Hibernate only expects to have at most one active transaction per session.

API documentation for Transaction wrote:
A transaction is associated with a Session and is usually instantiated by a call to Session.beginTransaction(). A single session might span multiple transactions since the notion of a session (a conversation between the application and the datastore) is of coarser granularity than the notion of a transaction. However, it is intended that there be at most one uncommitted Transaction associated with a particular Session at any time.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 7:41 pm 
Newbie

Joined: Tue Mar 21, 2006 1:42 pm
Posts: 14
This just seems to contradict javax.transaction.UserTransaction which the api for the begin() method states:

Code:
begin

public void begin()
           throws NotSupportedException,
                  SystemException

    Create a new transaction and associate it with the current thread.

    Throws:
>>>>>>>>NotSupportedException - Thrown if the thread is already associated with a transaction and the Transaction Manager implementation does not support nested transactions.<<<<<<<
        SystemException - Thrown if the transaction manager encounters an unexpected error condition.


I don't understand why Hibernate doesn't pass the responsibility of handling nested transactions to the underlying implementation. Also, if Hibernate wants "at most one uncommitted Transaction associated with a particular Session at any time," shouldn't multiple calls to beginTransaction() throw an exception if there is currently an active uncommitted transaction?

_________________
Mike Ringrose


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 2:21 pm 
Newbie

Joined: Thu Sep 22, 2005 7:40 am
Posts: 5
I agree, I don't understand the change and it is preventing me from upgrading :-(

/Konstantin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 3:18 pm 
Newbie

Joined: Thu Sep 22, 2005 7:40 am
Posts: 5
I have browsed through the changes of the JTATransaction somebody has made it possible to begin more transactions than you can commit? It used to throw an exception if "begun" was true but now it does not any more...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.