0 Replies Latest reply on Jan 28, 2013 6:14 PM by hotribao

    seam2-spring3 integration result ERROR [org.jboss.seam.contexts.Contexts] could not discover transaction status

    hotribao

      Hello,

       

      I am integrating Seam 2.2.2.final with Spring 3.2.0.RELEASE following this references

       

      The Spring's application context looks like

       

      {code:xml}

      <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

          <property name="jndiName" value="java:comp/env/myDatasource"/>   

        </bean>

       

        <bean id="springEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

          <property name="dataSource" ref="dataSource"/>

          <property name="persistenceUnitName" value="myPersistenceUnit"/>

          <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/>

          <property name="jpaDialect">

            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>

          </property>

          <property name="jpaVendorAdapter">

            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">

              <property name="showSql" value="false"/>

              <property name="generateDdl" value="false"/>

            </bean>

          </property>

          <property name="jpaProperties">

            <props>

              <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>

                          ....

            </props>

          </property>

        </bean>

       

        <bean id="entityManagerFactory" class="org.jboss.seam.ioc.spring.SeamManagedEntityManagerFactoryBean">

          <property name="persistenceContextName" value="entityManager"/>

          <property name="persistenceUnitName" value="myPersistenceUnit:seam"/>

        </bean>

       

        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">

         <property name="defaultPersistenceUnitName" value="myPersistenceUnit:seam"/>

        </bean>

       

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">

          <property name="entityManagerFactory" ref="springEntityManagerFactory"/>

        </bean>

      {code}

       

      My components.xml file looks like following

      {code:xml}

         <spring:spring-transaction platform-transaction-manager="#{transactionManager}"/>

         <persistence:managed-persistence-context name="entityManager" auto-create="true"

                                entity-manager-factory="#{springEntityManagerFactory}" />

      {code}

       

      1. First issue:

      As far as I understand, the springEntityManagerFactory has to be ONLY consumed by Seam. However, in the transactionManager bean (which is is a Spring's JpaTransactionManager), I have to inject the springEntityManagerFactory into it otherwise, I will get the following error if I inject the entityManagerFactory (which is a SeamManagedEntityManagerFactoryBean)

       

      {code}

      Caused by: java.lang.IllegalStateException: Seam application context not available and cannot be started.  Seam Managed Persistence Context not available.  Try placing the spring bean call inside of a spring transaction or try making the spring bean a Seam Component using <seam:component/>.

                at org.jboss.seam.ioc.spring.SeamLifecycleUtils.beginTransactionalSeamCall(SeamLifecycleUtils.java:44)

                at org.jboss.seam.ioc.spring.SeamManagedEntityManagerFactory.createEntityManager(SeamManagedEntityManagerFactory.java:58)

                at org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:444)

                at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:366)

      {code}

       

      It's strange because my Hessian call is already inside a transasaction demarcation.

      --> Is injecting the springEntityManagerFactory into the JpaTransactionManager correct?

       

       

      2. Second issue

      Now, with the springEntityManagerFactory injected to the JpaTransactionManager, I can invoke a Hessian call (exposed by Spring). However, I see the following error in the log

       

      {code}

        ERROR [org.jboss.seam.contexts.Contexts] could not discover transaction status

      {code}

       

      Source code of the class org.jboss.seam.contexts.Contexts shows that

       

      {code}

                  boolean transactionActive = false;

                  try

                  {

                     transactionActive = Transaction.instance().isActive();

                  }

                  catch (Exception e)

                  {

                     log.error("could not discover transaction status");

                  }

      {code}

       

      Stack trace of the exception shows

       

      {code}

      java.lang.IllegalStateException: Transaction not active

                at org.hibernate.ejb.TransactionImpl.getRollbackOnly(TransactionImpl.java:110)

                at org.springframework.orm.jpa.JpaTransactionManager$JpaTransactionObject.isRollbackOnly(JpaTransactionManager.java:657)

                at org.springframework.transaction.support.DefaultTransactionStatus.isGlobalRollbackOnly(DefaultTransactionStatus.java:156)

                at org.springframework.transaction.support.AbstractTransactionStatus.isRollbackOnly(AbstractTransactionStatus.java:71)

                at org.jboss.seam.ioc.spring.SpringTransaction.getStatus(SpringTransaction.java:171)

                at org.jboss.seam.transaction.AbstractUserTransaction.isActive(AbstractUserTransaction.java:27)

                at org.jboss.seam.contexts.Contexts.flushAndDestroyContexts(Contexts.java:331)

                at org.jboss.seam.contexts.Lifecycle.endCall(Lifecycle.java:101)

                at org.jboss.seam.ioc.spring.SeamLifecycleUtils$SeamLifecycleSynchronization.afterCompletion(SeamLifecycleUtils.java:72)

                at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCompletion(TransactionSynchronizationUtils.java:168)

                at org.springframework.transaction.support.AbstractPlatformTransactionManager.invokeAfterCompletion(AbstractPlatformTransactionManager.java:993)

                at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion(AbstractPlatformTransactionManager.java:968)

                at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:799)

                at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)

                at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:392)

                at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)

      {code}

       

      It's clearly that the method Contexts.flushAndDestroyContexts() in seam is called AFTER the transaction is commited by the Spring's transaction manager, thus, the transaction is always in state "INACTIVE" when enquired by seam.

       

      Is my configuration wrong (which leads to this error)? Or will I just safely ignore this error?

       

      Thanks in advance,

      Bao.