1 2 3 Previous Next 33 Replies Latest reply on Apr 10, 2012 11:08 AM by lightguard

    Seam transaction interceptor could not find transaction in jboss 7

    yangju.richard.yang.pearson.com
      I posted the same question in weld forum, but I am afraid Weld forum might not be the right place. Sorry for the double posting.

      My code works fine in jboss 6 (deployed as ear). Recently we migrated our code to jboss 7 (web profile) and deployed it as war. Now we got the following errors:
      java.lang.UnsupportedOperationException: no transaction
           at org.jboss.seam.transaction.NoTransaction.begin(NoTransaction.java:47) [seam-persistence-impl-3.0.0.Final.jar:]
           at org.jboss.seam.transaction.DefaultSeamTransaction.begin(DefaultSeamTransaction.java:102) [seam-persistence-impl-3.0.0.Final.jar:]
           at org.jboss.seam.transaction.Work.workInTransaction(Work.java:51) [seam-persistence-impl-3.0.0.Final.jar:]
           at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:188) [seam-persistence-impl-3.0.0.Final.jar:]

      The code is something like this:
      @TransactionAttribute
      @ApplicationScoped
      public class MyServiceImpl implements Serializable, MyService{
         
          @Inject
          @MyEM
          private EntityManager em;
        • 1. Re: Seam transaction interceptor could not find transaction in jboss 7
          lightguard

          This same question has been asked multiple times on the forums. You need to update to something more current than 3.0.0.Final, there was a bug wrt AS7 and the TransactionManager.

          • 2. Re: Seam transaction interceptor could not find transaction in jboss 7
            hantsy

            If this is a bug, i think it is a bug of JBoss 7 as...why change the jdni name?

            • 3. Re: Seam transaction interceptor could not find transaction in jboss 7
              lightguard

              There's actually no standard place to find the TransactionManager, so wherever an application server decides to bind it is up to them.


              In this particular case, I believe it was changed because there had been some problems in the past with people using it incorrectly, to lessen those problems the location was changed. Earlier, I don't even think it was available in JNDI.

              • 4. Re: Seam transaction interceptor could not find transaction in jboss 7
                yangju.richard.yang.pearson.com

                I upgraded to 3.1.0.Beta4 (bom). Now I could not deploy my war anymore. I got:
                Caused by: java.lang.ClassNotFoundException: org.jboss.seam.transaction.TransactionInterceptor


                Did the TransactionInterceptor get changed?


                Also, we are trying to use seam transaction for threads that our application creates. Does that work? The jboss 7 migration guide seems saying that UserTransaction is not supported in application thread.


                We are not using SMPC. Instead we just use @TransactionAttribute.



                • 5. Re: Seam transaction interceptor could not find transaction in jboss 7
                  yangju.richard.yang.pearson.com
                  I removed the TransactionInteceptor in the beans.xml and then reading from database appears to be OK. But when I tried to update database, I got error complaining about "Transaction is required".

                  (http-localhost-127.0.0.1-8080-3) init() error=Transaction is required to perform this operation (either use a transaction or extended persistence context): javax.persistence.TransactionRequiredException: Transaction is required to perform this operation (either use a transaction or extended persistence context)
                          at org.jboss.as.jpa.container.AbstractEntityManager.transactionIsRequired(AbstractEntityManager.java:686) [jboss-as-jpa-7.0.2.Final.jar:7.0.2.Final]
                          at org.jboss.as.jpa.container.AbstractEntityManager.persist(AbstractEntityManager.java:574) [jboss-as-jpa-7.0.2.Final.jar:7.0.2.Final]
                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]
                          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_24]
                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_24]
                          at java.lang.reflect.Method.invoke(Unknown Source) [:1.6.0_24]
                          at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                          at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                          at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                          at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                          at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:57) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                          at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                          at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                          at org.jboss.weldx.persistence.EntityManager$-197754958$Proxy$_$$_Weld$Proxy$.persist(EntityManager$-197754958$Proxy$_$$_Weld$Proxy$.java) [weld-core-1.1.2.Final.jar:]
                  • 6. Re: Seam transaction interceptor could not find transaction in jboss 7
                    lightguard

                    Mind pasting some code as well please? Also if you're not using the SMPC, you could simply remove the Persistence and Transaction modules. You could also easily create your own interceptor to do the same work.

                    • 7. Re: Seam transaction interceptor could not find transaction in jboss 7
                      yangju.richard.yang.pearson.com
                      I tried our webapp with no application managed thread and the transaction does not work with seam 3.1.0 beta3. It used to work fine with seam 3.0.0.Final.

                      Here is the code:

                      Persistence.xml

                      <persistence-unit name="Me">
                                <jta-data-source>java:jboss/datasources/Default-Database</jta-data-source>
                                <jar-file>lib/myPersistence.jar</jar-file>
                                <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>

                                <properties>
                                     <property name="hibernate.hbm2ddl.auto" value="none" />
                                     <!-- Inflexible approach to turn on sql logs as it writes them to console
                                          only; Use logger configuration instead -->
                                     <property name="hibernate.show_sql" value="true" />
                                     <property name="hibernate.transaction.flush_before_completion"
                                          value="true" />
                                     <property name="hibernate.dialect" value="some mysql string" />
                                     <property name="hibernate.jdbc.batch_size" value="50" />
                                     <property name="hibernate.order_inserts" value="true" />
                                     <property name="hibernate.order_updates" value="true" />

                                     <property name="hibernate.transaction.manager_lookup_class"
                                          value="org.hibernate.transaction.JBossTransactionManagerLookup" />
                                     <property name="jboss.entity.manager.factory.jndi.name"
                                          value="java:jboss/EntityManagerFactories/login/emf" />
                                          
                                     <property name="hibernate.cache.region.factory_class"
                                          value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />
                                     <property name="net.sf.ehcache.configurationResourceName"
                                          value="/cache-config.xml" />
                                          

                                     <property name="hibernate.cache.use_query_cache" value="true" />
                                     <property name="hibernate.cache.use_second_level_cache"
                                          value="true" />
                                     <property name="hibernate.cache.use_query_cache" value="true" />
                                     <property name="hibernate.generate_statistics" value="true" />

                                     

                                </properties>

                      </persistence-unit>

                      Service code (where transaction should start):
                      @TransactionAttribute
                      public class MyServiceImpl implements Serializable, MyService {
                          @Inject
                          @CentralEM
                          EntityManager em;

                          @Inject
                          UserDAO userDao;
                         
                          public void createTask(UserSession userSession, Task currentTask) {
                                  userDao.setEm(em);
                                  //update database
                                  userDao.createTask(userSession, currentTask);
                                 
                          }
                      }

                      Entity Manager Producer (we have multiple databases)
                      public class CentralEMProducer {

                          @CentralEM
                         
                          @Produces
                          @PersistenceContext(unitName = Constants.PERSISTENT_UNIT_CORE)
                          EntityManager em;

                      }

                      Dao class is very trivial and it takes an entitymanager instance passed from service layer. It is skipped here.

                      Error I got (deployment seems fine)

                      error=Transaction is required to perform this operation (either use a transaction or extended persistence context): javax.persistence.TransactionRequiredException: Transaction is required to perform this operation (either use a transaction or extended persistence context)
                           at org.jboss.as.jpa.container.AbstractEntityManager.transactionIsRequired(AbstractEntityManager.java:686) [jboss-as-jpa-7.0.2.Final.jar:7.0.2.Final]
                           at org.jboss.as.jpa.container.AbstractEntityManager.persist(AbstractEntityManager.java:574) [jboss-as-jpa-7.0.2.Final.jar:7.0.2.Final]
                           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]
                           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_24]
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_24]
                           at java.lang.reflect.Method.invoke(Unknown Source) [:1.6.0_24]
                           at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                           at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                           at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                           at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                           at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:57) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                           at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                           at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                           at org.jboss.weldx.persistence.EntityManager$1712453035$Proxy$_$$_Weld$Proxy$.persist(EntityManager$1712453035$Proxy$_$$_Weld$Proxy$.java) [weld-core-1.1.2.Final.jar:]



                      • 8. Re: Seam transaction interceptor could not find transaction in jboss 7
                        lightguard

                        Okay, I think I got it. Looks like you're trying to use the EJB annotation on a non-EJB. You'll need to use an interceptor like what Seam Transaction provides, create your own, or make your service an EJB.

                        • 9. Re: Seam transaction interceptor could not find transaction in jboss 7
                          yangju.richard.yang.pearson.com

                          In seam 3.0.0.Final, TransactionInteceptor can be specified in the beans.xml. But with 3.1.0, the TransactionInteceptor class does not exist anymore. Then which interceptor class I can use? Do I have to write my own interceptor for @TransactionAttribute?


                          If writing my own is the only option, could you give a link for some examples? Especially for nested transactions.


                          Thanks.

                          • 10. Re: Seam transaction interceptor could not find transaction in jboss 7
                            yangju.richard.yang.pearson.com

                            Never mind. I found the org.jboss.seam.transaction.TransactionInterceptor class in the new seam-transaction-3.1.0.Beta4.jar, which did not exist in seam 3.0.0.Final.


                            The transaction in non-thread code works now.

                            • 11. Re: Seam transaction interceptor could not find transaction in jboss 7
                              yangju.richard.yang.pearson.com
                              Although the transaction works for non-application managed thread, it does not work on application managed thread. It could be a jboss 7 issue. Just wonder if you know it.

                              at org.jboss.seam.transaction.NoTransaction.begin(NoTransaction.java:43) [seam-transaction-3.1.0.Beta4.jar:]
                                   at org.jboss.seam.transaction.DefaultSeamTransaction.begin(DefaultSeamTransaction.java:87) [seam-transaction-3.1.0.Beta4.jar:]
                                   at org.jboss.seam.transaction.Work.workInTransaction(Work.java:46) [seam-transaction-3.1.0.Beta4.jar:]
                                   at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:148) [seam-transaction-3.1.0.Beta4.jar:]
                                   at sun.reflect.GeneratedMethodAccessor85.invoke(Unknown Source) [:1.6.0_24]
                                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_24]
                                   at java.lang.reflect.Method.invoke(Unknown Source) [:1.6.0_24]
                                   at org.jboss.interceptor.proxy.InterceptorInvocation$InterceptorMethodInvocation.invoke(InterceptorInvocation.java:72) [jboss-interceptor-core-2.0.0.Alpha3.jar:2.0.0.Alpha3]
                                   at org.jboss.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:82) [jboss-interceptor-core-2.0.0.Alpha3.jar:2.0.0.Alpha3]
                                   at org.jboss.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:133) [jboss-interceptor-core-2.0.0.Alpha3.jar:2.0.0.Alpha3]
                                   at org.jboss.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:112) [jboss-interceptor-core-2.0.0.Alpha3.jar:2.0.0.Alpha3]
                                   at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:65) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                              • 12. Re: Seam transaction interceptor could not find transaction in jboss 7
                                yangju.richard.yang.pearson.com

                                It seems that Seam cannot find transaction in non-EE threads. Is this a jboss 7 issue or seam issue? Do you know any work around?

                                • 13. Re: Seam transaction interceptor could not find transaction in jboss 7
                                  lightguard

                                  Not sure, could you supply a test (arquillian preferred if you know it) please?

                                  • 14. Re: Seam transaction interceptor could not find transaction in jboss 7
                                    yangju.richard.yang.pearson.com
                                    I have written an Arquillian test on our service which is being used by a non-EE thread. It seems that if it runs as Arquillian test on this service (the service is injected directly into Arquillian), it works fine and transaction is found. However, if the service is used by a non-EE thread, then seam could not find transaction.

                                    I notice that in jboss 7, the global transaction jndi is now
                                    "java:/jboss/UserTransaction". I am using Seam 3.1.0Beta4. Does Seam's code was changed to look for jboss global transaction of this new jndi name?

                                    I have found a similar thread
                                    http://seamframework.org/Community/AS7QuartzAsyncTransactionsCouldNotDiscoverTransactionStatus

                                    Is there any work around as we are stuck.

                                    Thanks.
                                    1 2 3 Previous Next