使用OpenEntityManagerInViewFilter进行延迟初始化?

编程入门 行业动态 更新时间:2024-10-09 18:21:11
本文介绍了使用OpenEntityManagerInViewFilter进行延迟初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一点已经工作的JBoss webapp,和一个Lazy初始化问题。 因此我被建议调查在Spring和使用 OpenEntityManagerInViewFilter 。

I have a little already working JBoss webapp, and a Lazy initialisation problem. Therefore I was advised to investigate in Spring and use OpenEntityManagerInViewFilter.

但是我仍然得到错误,希望你能帮助我吗? 我还需要在我的应用程序中更改哪些内容才能使用Spring OEM过滤器?

Nevertheless I still get the error, hope you could help me? What else do I have to change in my app to make use of the Spring OEM Filter?

我的设置如下:

@Entity class Customer; @Stateless @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) class DaoService { @PersistenceContext EntityManager em; } @Named @RequestScoped class CustomerFacade;

+ jsf stuff。

+jsf stuff.

[javax.enterprise.resource.webcontainer.jsf.context] (http--127.0.0.1-8080-1) org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: domain.Customer.customerList, no session or session was closed

我这样设置: web.xml

I set it up like this: web.xml

<filter> <filter-name> OpenEntityManagerInViewFilter </filter-name> <filter-class> org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter </filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>flushMode</param-name> <param-value>AUTO</param-value> </init-param> </filter> <!-- Include this if you are using Hibernate --> <filter-mapping> <filter-name>OpenEntityManagerInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Spring config --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>

applicationContext.xml:

applicationContext.xml:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /> </property> <property name="jpaProperties"> <props> <prop key="hibernate.transaction.manager_lookup_class"> org.hibernate.transaction.JBossTransactionManagerLookup </prop> </props> </property> </bean>

persistence.xml:

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="java.sun/xml/ns/persistence" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation=" java.sun/xml/ns/persistence java.sun/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="primary"> <!-- If you are running in a production environment, add a managed data source, the example data source is just for proofs of concept! --> <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> <properties> <!-- Properties for Hibernate --> <property name="hibernate.hbm2ddl.auto" value="create-drop" /> <property name="hibernate.show_sql" value="false" /> </properties> </persistence-unit> </persistence>

基本上所有的设置。

推荐答案

确保您不访问旧实体(例如序列化的实体在上次请求的会话中)。

Make sure you don't access old entities (for example serialized ones in the session in previous request).

更多推荐

使用OpenEntityManagerInViewFilter进行延迟初始化?

本文发布于:2023-11-12 01:54:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580180.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   OpenEntityManagerInViewFilter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!