2 Replies Latest reply on Mar 11, 2009 2:27 AM by Luc Dew

    Spring integration issue

    Luc Dew Newbie

      Hi i am trying to integrate a Spring DAO layer into Seam.
      It works when the persistence context is not managed by Seam. When i try to use Seam Managed Persistence Context ( using Dan Allen's instructions of Seam in Action book), i get exceptions Session is closed .


      I annotated the method that calls the DAO with a @Transactional annotation but it still does not work:


      Here's the persistence.xml file :


      <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="ringtheweb" transaction-type="JTA">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:jdbc/ringtheweb-DS</jta-data-source>
            <properties>
                    <!-- Scan for annotated classes and Hibernate mapping XML files -->
                    <property name="hibernate.archive.autodetection" value="class, hbm"/>
                    <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                    <property name="jboss.entity.manager.factory.jndi.name" value="java:jdbc/ringtheweb-DS"/>
                        <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
                    <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                <property name="hibernate.transaction.flush_before_completion" value="true"/>              
                <property name="hibernate.transaction.auto_close_session"  value="true"/>
                <property name="hibernate.connection.release_mode" value="auto"/>
                <property name="hibernate.show.sql" value="true"></property>              
            </properties>
         </persistence-unit>
      </persistence>




      The Spring context file:



             <context:component-scan base-package="com.ringtheweb.persistence.dao" />  
              <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>   
              <tx:annotation-driven transaction-manager="transactionManager"/>
              <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
                      <property name="defaultPersistenceUnitName" value="ringtheweb:extended"></property>
              </bean>
              <bean id="springEntityManagerFactory"
                      class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
                              <property name="persistenceUnitName" value="ringtheweb"/>
          </bean>
          
          
          <bean id="entityManagerFactory" class="org.jboss.seam.ioc.spring.SeamManagedEntityManagerFactoryBean">
                      <property name="persistenceContextName" value="entityManager"/>
                      <property name="persistenceUnitName" value="ringtheweb:extended"/>
              </bean>
      
              <!-- JTA Transaction manager -->
              <bean id="transactionManager"
                      class="org.springframework.transaction.jta.JtaTransactionManager">
                      <property name="autodetectUserTransaction" value="true"></property>
              </bean>




      The components.xml :



          <persistence:managed-persistence-context
                              name="entityManager"
                              auto-create="true"
                              entity-manager-factory="#{springEntityManagerFactory}"/>
                              
              <spring:spring-transaction platform-transaction-manager-name="transactionManager"/>       
      



      Here's the code that creates the error:


      @Name("sipphonyLifeCycle")
      @Scope(ScopeType.APPLICATION)
      public class SipphonyLifeCycle {
              
              @Logger Log logger;
              
              @In("#{roleDAO}") IRoleDAO roleDAO; 
              
              @In("#{userManager}") IUserManager userManager;
              
                      
              @Observer("org.jboss.seam.postInitialization")  
              public void start() {
                      createDefaultRoles();
              }
              
      
              @Transactional
              public void createDefaultRoles() {
      
                      for (RoleType roleName : RoleType.values()) {
                              Role role = roleDAO.findByName(roleName.name());
                              if (null == role) {
                                      role = new Role(roleName.name(),"Role "+roleName.name());
                                      roleDAO.makePersistent(role);
                              }
                      }
                      
                      User user = new User();
                      user.setLoginName("admin");
                      user.setPassword("admin");
                      user.setEmail("root@localhost");
                      try {
                              userManager.saveUserInRole(user, RoleType.ADMIN);
                      }
                      catch(NonUniqueLoginException e) {
                              e.printStackTrace();
                      }
                      catch (RoleNotFoundException e) {
                              e.printStackTrace();
                      }
                      
              }
      



      In the above configuration if i don't use SMPC it means naming entity-manager-factory in components.xml : entityManagerFactory and setting defaultPersistenceUnitName to ringtheweb in Spring context file it works.


      But here's the error stack trace i get:





      15:28:02,953 ERROR Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.jboss.seam.servlet.SeamListener
      org.springframework.orm.jpa.JpaSystemException: org.hibernate.SessionException: Session is closed!; nested exception is javax.persistence.PersistenceException: org.hibernate.SessionException: Session is closed!
              at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:296)
              at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:352)
              at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:62)
              at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:212)
              at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:146)
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
              at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
              at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
              at $Proxy114.makePersistent(Unknown Source)
              at com.ringtheweb.web.lifecycle.SipphonyLifeCycle.createDefaultRoles(SipphonyLifeCycle.java:50)
              at com.ringtheweb.web.lifecycle.SipphonyLifeCycle.start(SipphonyLifeCycle.java:38)
              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.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
              at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:40)
              at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:34)
              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:166)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
              at com.ringtheweb.web.lifecycle.SipphonyLifeCycle$$javassist0.start(SipphonyLifeCycle$$javassist0.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.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:138)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2201)
              at org.jboss.seam.core.Events.raiseEvent(Events.java:85)
              at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:114)
              at org.jboss.seam.init.Initialization.init(Initialization.java:727)
              at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
              at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
              at org.apache.catalina.core.StandardContext.start(StandardContext.java:4361)
              at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
              at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
              at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
              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.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
              at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.apache.catalina.core.StandardContext.init(StandardContext.java:5312)
              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.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
              at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
              at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
              at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
              at org.jboss.web.WebModule.startModule(WebModule.java:83)
              at org.jboss.web.WebModule.startService(WebModule.java:61)
              at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
              at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
              at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
              at $Proxy0.start(Unknown Source)
              at org.jboss.system.ServiceController.start(ServiceController.java:417)
              at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
              at $Proxy44.start(Unknown Source)
              at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
              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.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
              at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
              at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
              at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
              at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
              at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
              at $Proxy45.start(Unknown Source)
              at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
              at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
              at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
              at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
              at $Proxy9.deploy(Unknown Source)
              at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
              at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
              at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
              at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336)
              at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
              at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
              at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
              at $Proxy0.start(Unknown Source)
              at org.jboss.system.ServiceController.start(ServiceController.java:417)
              at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
              at $Proxy4.start(Unknown Source)
              at org.jboss.deployment.SARDeployer.start(SARDeployer.java:304)
              at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
              at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
              at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
              at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
              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.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
              at $Proxy5.deploy(Unknown Source)
              at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
              at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
              at org.jboss.Main.boot(Main.java:200)
              at org.jboss.Main$1.run(Main.java:508)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.persistence.PersistenceException: org.hibernate.SessionException: Session is closed!
              at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
              at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:558)
              at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:442)
              at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.doJoinTransaction(ExtendedEntityManagerCreator.java:375)
              at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:343)
              at $Proxy166.joinTransaction(Unknown Source)
              at org.jboss.seam.persistence.EntityManagerProxy.joinTransaction(EntityManagerProxy.java:122)
              at org.jboss.seam.transaction.AbstractUserTransaction.enlist(AbstractUserTransaction.java:73)
              at org.jboss.seam.ioc.spring.SpringTransaction.enlist(SpringTransaction.java:262)
              at org.jboss.seam.persistence.ManagedPersistenceContext.joinTransaction(ManagedPersistenceContext.java:122)
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:111)
              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.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:138)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2201)
              at org.jboss.seam.Component.unwrap(Component.java:2227)
              at org.jboss.seam.Component.getInstance(Component.java:1994)
              at org.jboss.seam.Component.getInstance(Component.java:1940)
              at org.jboss.seam.Component.getInstance(Component.java:1934)
              at org.jboss.seam.Component.getInstance(Component.java:1929)
              at org.jboss.seam.ioc.spring.SeamManagedEntityManagerFactory.createEntityManager(SeamManagedEntityManagerFactory.java:59)
              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.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(AbstractEntityManagerFactoryBean.java:434)
              at $Proxy107.createEntityManager(Unknown Source)
              at org.springframework.orm.jpa.EntityManagerFactoryUtils.doGetTransactionalEntityManager(EntityManagerFactoryUtils.java:195)
              at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:174)
              at $Proxy110.merge(Unknown Source)
              at com.ringtheweb.persistence.dao.jpa.GenericJPADAO.makePersistent(GenericJPADAO.java:103)
              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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
              at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
              at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138)
              ... 174 more
      Caused by: org.hibernate.SessionException: Session is closed!
              at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
              at org.hibernate.impl.SessionImpl.getTransaction(SessionImpl.java:1314)
              at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:452)
              ... 214 more




        • 1. Re: Spring integration issue
          Luc Dew Newbie
          Ok i figured out what happened in this special case. The wrong method was annotated ( a component's internal method) and therefore it was not intercepted by the TransactionInterceptor.

          Also i found out that setting the hibernate.transaction.auto_close_session property to true cause a lot of issues in Seam with Seam Managed Persistence Context.

          Because for instance, in the SeamPhaseListener's afterServletPhase(PhaseEvent event) the following code is executed:

          handleTransactionsAfterPhase(event);
                     
          if ( event.getPhaseId() == RENDER_RESPONSE )
                {
                   afterRenderResponse(facesContext);
                }
                else if ( facesContext.getResponseComplete() )
                {
                   afterResponseComplete(facesContext);
                }

          If the current JSF phase is "after RENDER_RESPONSE" transaction is terminated (commited or rollbacked) by the handleTransactionsAfterPhaseMethod(event) method. If auto_close_session mode is set to true, the session is closed. But the afterRenderResponse(facesContext) is then executed. This method tries to change session's flush mode. Therefore, a "session is closed" warning appears !

          It should be documented that setting this parameter to true can cause this kind of errors in Seam. But not setting this parameter to true can cause Hibernate sessions leakage if the persistence context not handled by Seam. Also, i am not sure that in any Seam use cases, the managed persistence context is closed properly. Some examples a method annotated @Observer("org.jboss.seam.postInitialization") with or @Async...
          • 2. Re: Spring integration issue
            Luc Dew Newbie

            I created a bug report, see JBSEAM-4006