6 Replies Latest reply on Jul 10, 2007 4:14 PM by Przemyslaw Jaskierski

    Seam 2: is Spring integration totally broken?

    Przemyslaw Jaskierski Newbie

      Env: Tomcat 6.0.13, Spring 2.0.6, Seam CVS snapshot 08-07-2007.

      Task: I try to get Seam-managed hibernate session to work. Datasource and HibernateSessionFactory are wired by Spring. Then I want to get to that factory from within components.xml, to enable Seam-managed session.

      I tried both ways to integratie Seam-Spring described in manual. Both failed totally. Both attempts are listed below.

      components.xml is the same in both cases:

       <core:init debug="false"/>
      
       <core:manager conversation-timeout="120000"
       concurrent-request-timeout="500"
       conversation-id-parameter="k"/>
      
       <persistence:managed-hibernate-session name="pecpSeamManagedHibernateSession" auto-create="true"
       session-factory="#{hibernateSessionFactory}"/>
      
       <transaction:hibernate-transaction session="#{pecpSeamManagedHibernateSession}"/>
      



      1. Attempt: use <seam:component>: FAILED


      1.1 Spring context file:

      <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" scope="prototype">
       <seam:component name="hibernateSessionFactory" class="org.hibernate.impl.SessionFactoryImpl"/>
       <property name="dataSource" ref="dataSource" />
       <property name="configLocation" value="classpath:conf/hibernate/hibernate.cfg.xml" />
       <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
       <property name="namingStrategy">
       <bean class="pecp.persistence.hibernate.extensions.UnderscoreAwareNamingStrategy"/>
       </property>
       <property name="hibernateProperties">
       <props>
       <prop key="hibernate.hbm2ddl.auto">create</prop>
       </props>
       </property>
       </bean>
      


      1.2. Result: nasty exception at startup (in both cases - when Seam listener is before Spring listener in web.xml and the other way):

      * 2007-07-08 23:06:12,305 ERROR ContextLoader.initWebApplicationContext():203
       Context initialization failed
      org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [conf/spring/persistence-hibernate.xml]; nested exception is java.lang.IllegalStateException: No active application scope
      Caused by:
      java.lang.IllegalStateException: No active application scope
       at org.jboss.seam.core.Init.instance(Init.java:88)
       at org.jboss.seam.ioc.spring.SeamNamespaceHandler$SeamComponentBeanDefinitionDecorator.decorate(SeamNamespaceHandler.java:191)
       at org.springframework.beans.factory.xml.NamespaceHandlerSupport.decorate(NamespaceHandlerSupport.java:106)
       at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateIfRequired(BeanDefinitionParserDelegate.java:1143)
       at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1132)
       at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.processBeanDefinition(DefaultBeanDefinitionDocumentReader.java:237)
       at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:151)
       at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:130)
       at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:90)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:458)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:353)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:280)
       at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131)
       at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147)
       at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
       at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
       at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101)
       at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389)
       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324)
       at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
       at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
       at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
       at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)
       at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
       at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
       at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
       at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
       at org.apache.catalina.core.StandardService.start(StandardService.java:516)
       at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
       at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
       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.catalina.startup.Bootstrap.start(Bootstrap.java:288)
       at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
      Jul 8, 2007 11:06:12 PM org.apache.catalina.core.StandardContext listenerStart
      SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
      org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [conf/spring/persistence-hibernate.xml]; nested exception is java.lang.IllegalStateException: No active application scope
      Caused by: java.lang.IllegalStateException: No active application scope
       at org.jboss.seam.core.Init.instance(Init.java:88)
       at org.jboss.seam.ioc.spring.SeamNamespaceHandler$SeamComponentBeanDefinitionDecorator.decorate(SeamNamespaceHandler.java:191)
       at org.springframework.beans.factory.xml.NamespaceHandlerSupport.decorate(NamespaceHandlerSupport.java:106)
       at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateIfRequired(BeanDefinitionParserDelegate.java:1143)
       at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.decorateBeanDefinitionIfRequired(BeanDefinitionParserDelegate.java:1132)
       at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.processBeanDefinition(DefaultBeanDefinitionDocumentReader.java:237)
       at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:151)
       at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:130)
       at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:90)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:458)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:353)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
       at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:280)
       at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131)
       at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147)
       at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
       at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
       at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101)
       at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389)
       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324)
       at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
       at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
       at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
       at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)
       at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
       at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
       at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
       at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
       at org.apache.catalina.core.StandardService.start(StandardService.java:516)
       at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
       at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
       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.catalina.startup.Bootstrap.start(Bootstrap.java:288)
       at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
      Jul 8, 2007 11:06:12 PM org.apache.catalina.core.StandardContext start
      SEVERE: Error listenerStart
      



      2, Attempt: use EL resolver approach: FAILED:


      2.1 Spring context file:

      <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" scope="prototype">
       <property name="dataSource" ref="dataSource" />
       <property name="configLocation" value="classpath:conf/hibernate/hibernate.cfg.xml" />
       <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
       <property name="namingStrategy">
       <bean class="pecp.persistence.hibernate.extensions.UnderscoreAwareNamingStrategy"/>
       </property>
       <property name="hibernateProperties">
       <props>
       <prop key="hibernate.hbm2ddl.auto">create</prop>
       </props>
       </property>
       </bean>
      


      2.2 Spring EL resolver added to faces-config.xml,

      2.3 Result: Seam enters infinite loop, looks like it simply instantiates
      hibernateSessionFactory Spring bean over an over again.

        • 1. Re: Seam 2: is Spring integration totally broken?
          Przemyslaw Jaskierski Newbie

          Correction to point 2.3: Seam enters infinite loop AFTER HTTP REQUEST. It deploys normally.

          • 2. Re: Seam 2: is Spring integration totally broken?
            Przemyslaw Jaskierski Newbie

            Update: removing scope="prototype" from Spring bean definition helped with infinite loop in EL resolver case. But instead I get some huge (houndreds/thousands of lines) stracktraces similiar to the one below. Note: test harness that do not have Seam-managed session works fine. Everything was working fine on Seam 1.3.0 ALPHA/microcontainer.

            SEVERE: Session event listener threw exception
            org.hibernate.exception.GenericJDBCException: could not get next sequence value
             at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
             at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
             at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
             at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
             at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
             at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
             at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
             at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
             at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
             at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
             at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
             at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
             at org.hibernate.search.impl.FullTextSessionImpl.saveOrUpdate(FullTextSessionImpl.java:447)
             at org.jboss.seam.persistence.HibernateSessionProxy.saveOrUpdate(HibernateSessionProxy.java:345)
             at pecp.client.jsf.backers.userstate.UserStateBacker.sessionCreated(UserStateBacker.java:48)
             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:21)
             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:31)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
             at org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:49)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
             at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
            


            • 3. Re: Seam 2: is Spring integration totally broken?
              Przemyslaw Jaskierski Newbie


              I want to share, in case that someone is googling for a solution here:

              I managed to create this configuration:
              DataSource bound by Spring, HibernateSessionFactory bound by Spring, Seam-managed Session by creating a Seam delegate component "sessionFactoryDelegate" that wraps Spring-bound SessionFactory and serve it via EL, like this:

              <persistence:managed-hibernate-session name="pecpSeamManagedHibernateSession" auto-create="true"
              session-factory="#{sessionFactoryDelegate.sessionFactory}"/>

              I would prefer another solution but current Spring integration apparently does not allow me to do this (is broken?).

              • 4. Re: Seam 2: is Spring integration totally broken?
                youngm Novice

                Can you please file a bug with as much current information and configuration as you can muster? I plan to begin work on official Hibernate support in the spring-seam integration soon and some of this information could come in handy.

                Mike

                • 5. Re: Seam 2: is Spring integration totally broken?
                  youngm Novice

                  Also what happens if you use spring:context-loader instead of the Spring ContextLoaderListener?

                  http://docs.jboss.com/seam/2.0.0.B1/reference/en/html/spring.html#d0e12322

                  • 6. Re: Seam 2: is Spring integration totally broken?
                    Przemyslaw Jaskierski Newbie

                    Hi Mike!

                    I tried to do my best to reproduce my previous environment (with limited success). Hope it helps.

                    http://jira.jboss.org/jira/browse/JBSEAM-1636

                    Cheers,
                    Przemek.