4 Replies Latest reply on Mar 20, 2009 9:35 AM by Olivier Thierry

    Can't make Seam managed transactions work

    Olivier Thierry Apprentice

      Hi,


      I try to run POJOs / JavaBeans Seam components on OpenEJB 3.0. For what I understood, I need to use Seam managed persistence context and Seam managed transactions and I sould have the same beahaviour as EJB3 session beans.


      I could make Seam managed persistence context work thanks to Stuart Douglas help : http://www.seamframework.org/Community/SeammanagedPersistenceContextOnOpenEJB


      Now I try to configure Seam managed transactions but I can't make it work.


      The persistence.xml file is like this :


      <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_1_0.xsd"
          version="1.0">
          <persistence-unit name="t4Seam">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>java:/jdbc/t4Seam</jta-data-source>
              <mapping-file>META-INF/orm-utils.xml</mapping-file>
              <properties>
                  <property name="hibernate.hbm2ddl.auto" value="update"/>
                  <property name="hibernate.show_sql" value="false"/>
              </properties>
          </persistence-unit>
      </persistence>



      In components.xml I added this :


      <transaction:ejb-transaction />



      And my Seam components are like this :


      @Transactional(TransactionPropagationType.REQUIRED)
      public class FileAppenderDaoBase
          implements FileAppenderDao
      {
          @In
          protected javax.persistence.EntityManager emanager;
      
      ...
      }
      



      My unit tests call Groovy scripts that call my Saem components. It used to work when my Seam components were EJB3 session beans. But now they are POJOs I have the following stack trace :



      -------------------------------------------------------------------------------
      Test set: TestSuite
      -------------------------------------------------------------------------------
      Tests run: 66, Failures: 1, Errors: 0, Skipped: 64, Time elapsed: 12.094 sec <<< FAILURE!
      loadTestDatas(t4.core.utils.test.EJB3Container)  Time elapsed: 0.576 sec  <<< FAILURE!
      java.lang.reflect.InvocationTargetException
              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 t4.core.utils.test.EJB3Container$2.testComponents(EJB3Container.java:39)
              at org.jboss.seam.mock.AbstractSeamTest$ComponentTest.run(AbstractSeamTest.java:162)
              at t4.core.utils.test.EJB3Container.loadTestDatas(EJB3Container.java:34)
      Caused by: java.lang.UnsupportedOperationException: no transaction
              at org.jboss.seam.transaction.NoTransaction.begin(NoTransaction.java:36)
              at org.jboss.seam.util.Work.workInTransaction(Work.java:42)
              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:89)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
              at t4.core.utils.trace.internal.FileAppenderDaoBase_$$_javassist_0.create(FileAppenderDaoBase_$$_javassist_0.java)
              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.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
              at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:230)
              at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:912)
              at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:756)
              at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:766)
              at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:754)
              at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170)
              at t4.core.utils.groovy.TraceTestData.run(TraceTestData.groovy:24)
              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.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
              at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:230)
              at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:912)
              at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:756)
              at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:778)
              at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:758)
              at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170)
              at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod0(ScriptBytecodeAdapter.java:198)
              at t4.core.utils.groovy.TestDataInitializer.run(TestDataInitializer.groovy:10)
              ... 36 more



      Anyone has an idea what happens ?


      I have one more question about using both Seam components as EJB3 session beans or POJOs. I mean that a Seam EJB3 session bean could call a Seam POJO. Do these both components share persistence context (if I inject Seam managed persistence context of course) and transactions ?


      Thanks in advance,


      Olivier

        • 1. Re: Can't make Seam managed transactions work
          Guillaume Jeudy Master

          Do you only get this stack trace in testNG integration testing? What about your project deployed in the real server?


          Can you show full snippet of components.xml including persistence: elements ?

          • 2. Re: Can't make Seam managed transactions work
            Stuart Douglas Master

            Try putting the following in your persistence.xml


            <property name="hibernate.transaction.manager_lookup_class"
                            value="org.apache.openejb.hibernate.TransactionManagerLookup"/>
            

            • 3. Re: Can't make Seam managed transactions work
              Olivier Thierry Apprentice

              I tried it but it changes nothing :(

              • 4. Re: Can't make Seam managed transactions work
                Olivier Thierry Apprentice

                Guillaume Jeudy wrote on Mar 19, 2009 19:26:


                Do you only get this stack trace in testNG integration testing? What about your project deployed in the real server?


                I use OpenEJB for unit tests only (I use it instead of JBoss embedded because I encountered some bugs with it). But I am going to try to deploy it on JBoss AS so that I will know if it is a problem with OpenEJB only or if I made some errors in my Seam components.



                Guillaume Jeudy wrote on Mar 19, 2009 19:26:

                Can you show full snippet of components.xml including persistence: elements ?


                Of course :


                <?xml version="1.0" encoding="UTF-8"?>
                <components xmlns="http://jboss.com/products/seam/components"
                    xmlns:core="http://jboss.com/products/seam/core"
                    xmlns:bpm="http://jboss.com/products/seam/bpm"
                    xmlns:persistence="http://jboss.com/products/seam/persistence"
                    xmlns:security="http://jboss.com/products/seam/security"
                    xmlns:framework="http://jboss.com/products/seam/framework"
                    xmlns:transaction="http://jboss.com/products/seam/transaction"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation=
                        "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd 
                        http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd 
                        http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd 
                        http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                        http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.0.xsd
                        http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
                
                    <core:init jndi-pattern="#{ejbName}/Local" debug="false" />
                     
                    <transaction:ejb-transaction />
                
                    <persistence:managed-persistence-context 
                         name="emanager" 
                     auto-create="true"
                     entity-manager-factory="#{entityManagerFactory}" />
                
                </components>



                And entityManagerFactory Seam component is like this :


                @Stateless
                @Name("entityManagerFactory")
                public class EntityManagerFactoryHackBean implements EntityManagerFactoryHackLocal {
                     
                     @PersistenceUnit(name="t4Seam")
                     EntityManagerFactory entityManagerFactory;
                     
                     @Unwrap
                     public EntityManagerFactory getEntityMangagerFactory()
                     {
                          return entityManagerFactory;
                     }
                
                
                }