6 Replies Latest reply on Mar 2, 2012 11:31 AM by hantsy bai

    Multiple DataSource Can not rollback the transaction in Seam.3.1.0.Final and Jboss.7.1.0.Final

    Feng Jiang Newbie

      Hi,

           I am trying using multiple datasources in my seam3 application. I injected two entitymanager in a bean and used them in a same method.  But i find that when the last save method failed , the previous method will not rollback.

       

           There is no any error in the console at the start-time .  So i change the log level at DEBUG in the Jboss.7.1.0.Final . There is some debug messages about the transaction which seamed miss some classes  in the logger.

       

       

      17:26:10,114 DEBUG [org.jboss.tm.TransactionManagerLocator] (MSC service thread 1-3) Unable to lookup: java:/TransactionManager: javax.naming.NameNotFoundException: Error looking up TransactionManager, service service jboss.naming.context.java.TransactionManager is not started
                at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:126) [jboss-as-naming-7.1.0.Final.jar:7.1.0.Final]
                at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:74) [jboss-as-naming-7.1.0.Final.jar:7.1.0.Final]
                at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:177) [jboss-as-naming-7.1.0.Final.jar:7.1.0.Final]
                at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113) [jboss-as-naming-7.1.0.Final.jar:7.1.0.Final]
                at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:213) [jboss-as-naming-7.1.0.Final.jar:7.1.0.Final]
                at javax.naming.InitialContext.lookup(InitialContext.java:392) [rt.jar:1.6.0_10-rc2]
                at org.jboss.tm.TransactionManagerLocator.tryJNDI(TransactionManagerLocator.java:150) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final]
                at org.jboss.tm.TransactionManagerLocator.locate(TransactionManagerLocator.java:131) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final]
                at org.jboss.tm.TransactionManagerLocator.locateTransactionManager(TransactionManagerLocator.java:94) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final]
                at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.<init>(ServerVMClientUserTransaction.java:93) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final]
                at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.<clinit>(ServerVMClientUserTransaction.java:60) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final]
                at org.jboss.as.txn.service.ArjunaTransactionManagerService.start(ArjunaTransactionManagerService.java:115) [jboss-as-transactions-7.1.0.Final.jar:7.1.0.Final]
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_10-rc2]
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_10-rc2]
                at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_10-rc2]
      
      
      17:26:10,149 DEBUG [org.jboss.tm.TransactionManagerLocator] (MSC service thread 1-3) Unable to instantiate legacy transaction manager: java.lang.ClassNotFoundException: org.jboss.tm.TxManager from [Module "org.jboss.jboss-transaction-spi:main" from local module loader @f30494 (roots: C:\Java\jboss-as-7.1.0.Final\modules)]
                at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
                at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
                at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
                at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) [rt.jar:1.6.0_10-rc2]
                at java.lang.Class.forName0(Native Method) [rt.jar:1.6.0_10-rc2]
                at java.lang.Class.forName(Class.java:169) [rt.jar:1.6.0_10-rc2]
                at org.jboss.tm.TransactionManagerLocator.usePrivateAPI(TransactionManagerLocator.java:172) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final]
                at org.jboss.tm.TransactionManagerLocator.locate(TransactionManagerLocator.java:133) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final]
                at org.jboss.tm.TransactionManagerLocator.locateTransactionManager(TransactionManagerLocator.java:94) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final]
                at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.<init>(ServerVMClientUserTransaction.java:93) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final]
                at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.<clinit>(ServerVMClientUserTransaction.java:60) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final]
                at org.jboss.as.txn.service.ArjunaTransactionManagerService.start(ArjunaTransactionManagerService.java:115) [jboss-as-transactions-7.1.0.Final.jar:7.1.0.Final]
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_10-rc2]
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_10-rc2]
                at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_10-rc2]
      
      

       

       

           In Jboss.7.1.0.Final the transaction jar is jboss-transaction-spi-7.0.0.Final.jar .  There is no a class named  org.jboss.tm.TxManager

       

           Has someone used the multiple datasources in the application successfully?

       

          Maybe i miss some jars? Or Seam.3.1.0.Final is not Supported the Multiple DataSources?

        • 1. Re: Multiple DataSource Can not rollback the transaction in Seam.3.1.0.Final and Jboss.7.1.0.Final
          Jason Porter Master

          Not sure if we've tried with multiple datasources. I know I haven't.

          • 2. Re: Multiple DataSource Can not rollback the transaction in Seam.3.1.0.Final and Jboss.7.1.0.Final
            Feng Jiang Newbie

            My multiple datasources configuration and some related classes.

             

            My persistence.xml

             

            <?xml version="1.0" encoding="UTF-8"?>

            <persistence 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"

                      version="2.0">

                      <persistence-unit name="JBossSeam3" transaction-type="JTA">

                                <jta-data-source>java:jboss/MySqlDS</jta-data-source>

                                <provider>org.hibernate.ejb.HibernatePersistence</provider>

                                <properties>

                                          <property name="hibernate.show_sql" value="true" />

                                          <property name="hibernate.transaction.manager_lookup_class"

                                                    value="org.hibernate.transaction.JBossTransactionManagerLookup" />

                                          <property name="hibernate.archive.autodetection" value="class" />

                                          <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />

                                </properties>

                      </persistence-unit>

             

                      <persistence-unit name="JBossSeam" transaction-type="JTA">

                                <jta-data-source>java:jboss/MySql2</jta-data-source>

                                <provider>org.hibernate.ejb.HibernatePersistence</provider>

                                <properties>

                                          <property name="hibernate.show_sql" value="true" />

                                          <property name="hibernate.transaction.manager_lookup_class"

                                                    value="org.hibernate.transaction.JBossTransactionManagerLookup" />

                                          <property name="hibernate.archive.autodetection" value="class" />

                                          <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />

                                </properties>

                      </persistence-unit>

            </persistence>

             

            EntityManagerProducer.java    @Jpa  is a Qualifier.

             

            public class EntityManagerProducer

            {

               @PersistenceUnit( unitName = "JBossSeam3")

               @ExtensionManaged

               @ConversationScoped

               @Produces

               @Jpa(name="frame")

               EntityManagerFactory emf;   

              

               @PersistenceUnit( unitName = "JBossSeam")

               @ExtensionManaged

               @ConversationScoped

               @Produces

               @Jpa(name="other")

               EntityManagerFactory emf2;   

            }

             

            TestAction.java     The two CRUD service each injected the entitymanager respectively.

             

              @Inject CRUDService crud;

                      @Inject CRUDService2 crud2;

             

            public void test(){

                                Test test = new Test("11");

                                curd2.add(test);

                                curd.add(test);

            }

            • 3. Re: Multiple DataSource Can not rollback the transaction in Seam.3.1.0.Final and Jboss.7.1.0.Final
              Feng Jiang Newbie

              In actual projects, mutil-datasource is often used . So please have a try , think you.

              • 4. Re: Multiple DataSource Can not rollback the transaction in Seam.3.1.0.Final and Jboss.7.1.0.Final
                Ove Ranheim Novice

                According to your error it's not able to lookup your transaction manager, because you point to the wrong JNDI name.

                 

                In AS 7.x JNDI names are changed. What used to be java: is now java:jboss. So try to change your JNDI lookup to: java:jboss/TransactionManager

                 

                Further, if you use Hibernate 4 (default in AS7) you should not use:

                 

                <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />

                 

                This will be configured by AS7 SPIs for you. You should also conduct the JBoss AS 7 docs to consolidate your configuration.

                 

                Hope this helps!

                • 5. Re: Multiple DataSource Can not rollback the transaction in Seam.3.1.0.Final and Jboss.7.1.0.Final
                  Feng Jiang Newbie

                  Thank you for reply .   Do you have a try use multile datasource in seam3 ?  The seam transaction hsa a problem when rollback. Multil-datasource is very important and often used in our application.  Do i have to give up Seam-Transaction ?

                  • 6. Re: Multiple DataSource Can not rollback the transaction in Seam.3.1.0.Final and Jboss.7.1.0.Final
                    hantsy bai Master

                    Try the following approaches.

                     

                    1. Verify your datasource JDNI  configurations if they used XAResource version.

                    2. Declare @Transcational on your method which have operations from two datasource.

                    3. Do not use Seam 3 transaction, and use original EJB TransactionAttribute instead, and verify if it is a Seam3 bug.