myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paolo ChilĂ " <paolo.ch...@gmail.com>
Subject [ORCHESTRA] - Problem restoring PersistenceContext in conversation
Date Fri, 18 Apr 2008 11:05:54 GMT
Hi,

I'm trying to use MyFaces Orchestra in my JSF 1.1 application using
Hibernate Entity Manager as JPA Provider and Tomcat 5.5.

I have a problem when using the EntityManager inside a conversation (all
pages are inside anonymous conversations since I use a single bean behind
each page):

- The first time I load a page the EntityManager is injected correctly
(inside the init() method of the page I can make queries etc.)
- After the page is rendered for the first time, calling an action (a
method) on that page i get the following exception

INFO  12:51:00,222         FWBasePage,263 Pagina: class
it.reply.fpt.estesa.fe.InserimentoUtentePage, action-method: doCercaUtente
DEBUG 12:51:00,222 erimentoUtentePage,291 cerca utente
DEBUG 12:51:00,222 edBeanTargetSource,70  getRealBean for
inserimentoUtentePageBean
DEBUG 12:51:00,222 ringOrchestraScope,309 getRealBean called for bean
inserimentoUtentePageBean
DEBUG 12:51:00,222 edBeanTargetSource,70  getRealBean for
inserimentoUtentePageBean
DEBUG 12:51:00,222 ringOrchestraScope,309 getRealBean called for bean
inserimentoUtentePageBean
DEBUG 12:51:00,237 edBeanTargetSource,70  getRealBean for
inserimentoUtentePageBean
DEBUG 12:51:00,237 ringOrchestraScope,309 getRealBean called for bean
inserimentoUtentePageBean
DEBUG 12:51:00,237 rInvocationHandler,185 Creating new EntityManager for
shared EntityManager invocation
DEBUG 12:51:00,237 anagerFactoryUtils,311 Closing JPA EntityManager
DEBUG 12:51:00,237 eBeanPhaseListener,27  ViewId corrente:
/pages/admin/gestioneAnagrafica.xhtml
DEBUG 12:51:00,237 edBeanTargetSource,70  getRealBean for
gestioneAnagraficaPageBean
DEBUG 12:51:00,237 ringOrchestraScope,309 getRealBean called for bean
gestioneAnagraficaPageBean
DEBUG 12:51:00,237 edBeanTargetSource,70  getRealBean for
gestioneAnagraficaPageBean
DEBUG 12:51:00,237 ringOrchestraScope,309 getRealBean called for bean
gestioneAnagraficaPageBean
DEBUG 12:51:00,237 esContextFactory$1,129 Running release
DEBUG 12:51:00,237 sfFrameworkAdapter,69  Ending request
DEBUG 12:51:00,237 esContextFactory$1,138 Release completed
DEBUG 12:51:00,237 essionInViewFilter,207 Closing single Hibernate Session
in OpenSessionInViewFilter
DEBUG 12:51:00,237 essionFactoryUtils,774 Closing Hibernate Session
ERROR 12:51:00,237 andardWrapperValve,253 Servlet.service() for servlet
Faces Servlet threw exception
org.hibernate.SessionException: Session is closed!
    at
org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1110)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)
    at
it.reply.fpt.estesa.fe.InserimentoUtentePage.doCercaUtente(InserimentoUtentePage.java:348)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at it.reply.fw2.fe.jsf.bean.FWBasePage.doAction(FWBasePage.java:267)
    at
it.reply.fw2.fe.jsf.bean.FWBasePage$$FastClassByCGLIB$$9162783.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:628)
    at
it.reply.fpt.estesa.fe.InserimentoUtentePage$$EnhancerByCGLIB$$9bf81719.doAction(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.el.parser.AstValue.invoke(Unknown Source)
    at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
    at
com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
    at
com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
    at
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
    at javax.faces.component.UICommand.broadcast(UICommand.java:109)
    at
org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:62)
    at
org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:184)
    at
org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:162)
    at
org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:350)
    at
org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
    at
org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
    at
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
    at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at
org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:420)
    at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
    at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
    at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)

As you can see in this case the EntityManager is created and then closed
immediately.
In both methods i use the same annotation @Transactional(readOnly=true,
propagation=Propagation.REQUIRED),

My orchestraConfiguration.xml:

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

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
               http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

  <!-- 1. initialization of all orchestra modules (required for core15
module) -->
  <import resource="classpath*:/META-INF/spring-orchestra-init.xml" />

  <!-- 2. the conversation scopes -->
  <bean
class="org.springframework.beans.factory.config.CustomScopeConfigurer">
    <property name="scopes">
      <map>
        <entry key="conversation.manual">
          <bean
class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
            <property name="timeout" value="30" />
            <property name="advices">
              <list>
                <ref bean="persistentContextConversationInterceptor"/>
              </list>
            </property>
          </bean>
        </entry>

        <entry key="conversation.access">
          <bean
class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
            <property name="timeout" value="30" />
            <property name="advices">
              <list>
                <ref bean="persistentContextConversationInterceptor"/>
              </list>
            </property>
            <property name="lifetime" value="access"/>
          </bean>
        </entry>
      </map>
    </property>
  </bean>

  <!-- 3. the "entity manager" manager -->
  <bean id="persistentContextConversationInterceptor"

class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor">
    <property name="persistenceContextFactory"
ref="persistentContextFactory"/>
  </bean>

  <!-- 4. conversation - persistence adapter -->
  <bean id="persistentContextFactory"

class="org.apache.myfaces.orchestra.conversation.spring.JpaPersistenceContextFactory">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
  </bean>

  <!-- 5. persistence -->
  <bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

  <tx:annotation-driven />

  <bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
  </bean>

   <bean id="entityManagerFactory"

class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

    <property name="jpaProperties">
      <props>
           <prop
key="hibernate.session_factory_name">hibernate/FptSessionFactory</prop>
           <prop key="hibernate.show_sql">true</prop>
           <prop key="hibernate.format_sql">true</prop>
      </props>
    </property>

    <property name="jpaVendorAdapter">

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

    </property>

    <property name="persistenceUnitName" value="FptEstesaJPA"/>
  </bean>


</beans>

and my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">
    <persistence-unit name="FptEstesaJPA" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:comp/env/jdbc/FPTEstesa</jta-data-source>
      <properties>
         <property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect"/>
         <property name="hibernate.show_sql" value="true"/>
      </properties>


    </persistence-unit>
</persistence>

I tried to look for examples of configuration for Orchestra + Hibernate +
JTA + Tomcat but I couldn't find any. It seems a matter of wrong
configuration to me but I don't know where to look, so any advice will be
greately appreciated.

Sorry for the length of this mail, but I found orchestra's features amazing
and I'd really like to use it in my project.

Thanks for your time and keep up the good work!

Paolo ChilĂ 

Mime
View raw message