You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Reto Breitenmoser <re...@gmail.com> on 2010/12/05 01:23:02 UTC

Orchestra, Spring and AspectJ

Hi

I'm having LazyInitializationException in my web application even if I'm 
using Orchestra's conversation scope. I checked already my Spring and 
Orchestra configurations and everything should be ok. Has it maybe 
something to do because I use the AspectJ support from Spring for the 
annotated transactions? I can see in my log files, that at the end of 
the transaction the entity manager is always closed and thats definitly 
not what I want when I use the conversation scope:

DEBUG [http-8080-5] org.hibernate.engine.StatefulPersistenceContext 
initializing non-lazy collections
TRACE [http-8080-5] org.hibernate.jdbc.JDBCContext after autocommit
DEBUG [http-8080-5] org.hibernate.jdbc.ConnectionManager aggressively 
releasing JDBC connection
TRACE [http-8080-5] org.hibernate.impl.SessionImpl after transaction 
completion
DEBUG [http-8080-5] 
org.springframework.orm.jpa.EntityManagerFactoryUtils Closing JPA 
EntityManager
TRACE [http-8080-5] org.hibernate.impl.SessionImpl closing session
TRACE [http-8080-5] org.hibernate.jdbc.ConnectionManager connection 
already null in cleanup : no action
ERROR [http-8080-5] org.hibernate.LazyInitializationException failed to 
lazily initialize a collection of role:

The handling from the JSF beans works perfect, I have only the problem 
with the persistence.

The application run's on tomcat6 (with the spring-instrument-tomcat.jar 
in the classpath), Spring 3.0.3 and JPA 2.0 (Hibernate).

Best regards,
Reto


And here is the application.xml configuration:


<?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" 
xmlns:context="http://www.springframework.org/schema/context"
     xmlns:p="http://www.springframework.org/schema/p" 
xmlns:jee="http://www.springframework.org/schema/jee"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
                    
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                    http://www.springframework.org/schema/tx
                    
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                    http://www.springframework.org/schema/context
                 
http://www.springframework.org/schema/context/spring-context-3.0.xsd
                 http://www.springframework.org/schema/jee
                 
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
                 http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<context:component-scan base-package="com.*" />
<context:load-time-weaver/>
<context:spring-configured />
<tx:annotation-driven mode="aspectj"/>
<aop:config proxy-target-class="true" />

<!-- 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>

<!-- View-Scope registrieren -->
<entry key="view">
<bean class="org.primefaces.spring.scope.ViewScope" />
</entry>
</map>
</property>
</bean>

<!-- 3. the "entity manager" manager -->
<bean id="persistentContextConversationInterceptor"
         
class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor">
<property name="persistenceContextFactory" 
ref="persistenceContextFactory" />
</bean>

<!-- 4. conversation - persistence adapter -->
<bean id="persistenceContextFactory"
         
class="org.apache.myfaces.orchestra.conversation.spring.JpaPersistenceContextFactory">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

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


<!-- Configure a c3p0 pooled data source -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="*****" />
<property name="password" value="*****" />
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="**********" />
<property name="initialPoolSize" value="1" />
<property name="minPoolSize" value="1" />
<property name="maxPoolSize" value="10" />
</bean>

<bean id="entityManagerFactory"
         
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="POSTGRESQL" />
</bean>
</property>
<property name="persistenceUnitName" value="******" />
<property name="loadTimeWeaver">
<bean
                 
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" 
/>
</property>
</bean>


<!-- Configure transaction manager for JPA -->
<bean id="transactionManager" 
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
</beans>