Atomikos Forum

Atomikos transactions throws an exception

Hi

Warm greetings for the day

I am running tomcat 7/Stateless beans with weld, The transaction throws me this exception:
WARNING: This method needs a transaction for the calling thread and none exists.
Possible causes: either you didn't start a transaction,
it rolledback due to timeout, or it was committed already.
ACTIONS: You can try one of the following:
1. Make sure you started a transaction for the thread.
2. Make sure you didn't terminate it yet.
3. Increase the transaction timeout to avoid automatic rollback of long transactions;
  check http://www.atomikos.com/Documentation/JtaProperties for how to do this.
java.lang.IllegalStateException: This method needs a transaction for the calling thread and none exists.
Possible causes: either you didn't start a transaction,
it rolledback due to timeout, or it was committed already.
ACTIONS: You can try one of the following:
1. Make sure you started a transaction for the thread.
2. Make sure you didn't terminate it yet.
3. Increase the transaction timeout to avoid automatic rollback of long transactions;
  check http://www.atomikos.com/Documentation/JtaProperties for how to do this.
    at com.atomikos.icatch.jta.TransactionManagerImp.raiseNoTransaction(TransactionManagerImp.java:123)
    at com.atomikos.icatch.jta.TransactionManagerImp.setRollbackOnly(TransactionManagerImp.java:536)
    at com.atomikos.icatch.jta.UserTransactionManager.setRollbackOnly(UserTransactionManager.java:226)
    at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:959)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1177)
    at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:691)
    at com.test.sessionfacade.AbstractFacade.remove(AbstractFacade.java:95)
    at com.test.controllers.controller.AbstractController.persist(AbstractController.java:175)
    at com.test.controllers.controller.AbstractController.delete(AbstractController.java:147)
    at com.test.controllers.controller.AdminUserController$Proxy$_$$_WeldClientProxy.delete(Unknown Source)
    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:597)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:264)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:147)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)

The code is given below:
@Transactional
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void remove(T entity) {
      EntityManager em =  getEntityManager();
      if(!em.isOpen())
          em = ApplicationListener.getEntityManagerFactory().createEntityManager();
    try{         
      em.setFlushMode(FlushModeType.COMMIT);
      em.remove(getEntityManager().merge(entity));
      em.close(); 
    }
    catch(Exception e)
    {
        e.printStackTrace();
    em.close();
        throw new IllegalStateException(e);
    }
        }

In my persistence.xml

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="chikujiPU" transaction-type="JTA">
     
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:comp/env/persistence/chikujiPU</jta-data-source>
   
    <class>com.test.model.AdminUser</class>
        <property value="org.hibernate.dialect.MySQLDialect" name="hibernate.dialect"/>
            <property value="jdbc:mysql://localhost:3306/test" name="javax.persistence.jdbc.url"/>
            <property value="password" name="javax.persistence.jdbc.password"/>
            <property value="com.mysql.jdbc.Driver" name="javax.persistence.jdbc.driver"/>
            <property value="root" name="javax.persistence.jdbc.user"/>
            <property value="org.hibernate.cache.NoCacheProvider" name="hibernate.cache.provider_class"/>
            <property value="none" name="javax.persistence.validation.mode"/>
            <property value="true" name="hibernate.show_sql"/>
            <property name="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>
      <!--</properties>-->
    </properties>
  </persistence-unit>
</persistence>

Regards
Sentil
senthil Send private email
Saturday, August 16, 2014
 
 
Hi

Thanks for giving me an opportunity for forum post. The problem is that I was using BMT rather CMT, now the issue is solved with the help of this link http://piotrnowicki.com/2012/11/types-of-entitymanagers-application-managed-entitymanager/

The following code :
@Resource(name="TransactionManager")
private UserTransaction utx;

  public void edit(T entity) throws IllegalStateException, SecurityException, SystemException {
      EntityManager em =  getEntityManager();
        try{

    utx.begin();
   
            em.setFlushMode(FlushModeType.COMMIT);
            em.joinTransaction();
            em.merge(entity);;
    utx.commit();
      }
      catch(Throwable e)
      {
          e.printStackTrace();
          utx.rollback();
          throw new IllegalStateException(e);
      }
}
works in tomcat7.
Regards
Sentil
senthil Send private email
Tuesday, August 19, 2014
 
 

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

Other recent topics Other recent topics