Results 1 to 4 of 4

Thread: Spring DM + OpenEntityManagerInView pattern LazyInitialization exception

Threaded View

  1. #1

    Default Spring DM + OpenEntityManagerInView pattern LazyInitialization exception

    Hi,

    I'm trying to implement the OEMIV pattern but am running into problems. I've spent a few days trawling forum posts, but am not much the wiser. Essentially the transaction manager doesn't seem to be aware of the opened session.

    I'm using Hibernate as the JPA implementation, and have separate bundles implementing the data model, and the actual vendor specific DAO. I've configured the entitymanager and transaction manager in the Hibernate DAO bundle and exposed them as services thus (only posting relevant bits):

    Bean declaration
    Code:
    	<bean id="testEMF" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="testDS"/>
    		<property name="persistenceUnitName" value="TestPU"/>
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				 <property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect"/> 
    				 <property name="generateDdl" value="false"/>
    				 <property name="showSql" value="true"/>
    			</bean>
    		</property>
    	</bean>
    
    	<bean id="testTM" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="testEMF"/>
    	</bean>
    Service export
    Code:
    	<service ref="testTM" interface="org.springframework.transaction.PlatformTransactionManager"/>
    	<service ref="testEMF" interface="javax.persistence.EntityManagerFactory"/>
    I've defined my webapp application context in applicationContext.xml and test-console-servlet.xml with contents as follows (omitting namespace declarations):

    applicationContext.xml
    Code:
    	<osgi:reference id="componentSvc"
    		interface="org.tssg.test.dataaccess.service.ComponentService" />
    		
    	<osgi:reference id="testEMF"
    		interface="javax.persistence.EntityManagerFactory" />
    test-console-servlet.xml
    Code:
    	<context:component-scan base-package="org.tssg.test.web.dashboard.web" />
    	
    	<bean
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    		p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
    web.xml (relevant bits)
    Code:
    	<filter>
    		<filter-name>openEntityManagerInViewFilter</filter-name>
    		<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
    		<init-param>
    			<param-name>entityManagerFactoryBeanName</param-name>
    			<param-value>testEMF</param-value>
    		</init-param>
    	</filter>
    
    	<filter-mapping>
    		<filter-name>openEntityManagerInViewFilter</filter-name>
    		<url-pattern>*.do</url-pattern>
    	</filter-mapping>
    
    	<context-param>
    		<param-name>contextClass</param-name>
    		<param-value>com.springsource.server.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
    	</context-param>
    
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    
    	<servlet>
    		<servlet-name>test-console</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<load-on-startup>2</load-on-startup>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>test-console</servlet-name>
    		<url-pattern>*.do</url-pattern>
    	</servlet-mapping>
    I'll post the log output in a reply, as if I include it here, I run into the 10k limit, so I'll comment on that there.

    I've also attached a stripped down Maven project that should hopefully import cleanly if anybody wants to try it. I'm deploying to DM Server btw

    (to be continued)

    John McLaughlin
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •