0

So I realize a Java EE web application (PrimeFaces, Spring, Hibernate) during advancement in programming, I found that all the association between class type Lazy does not always work ("error-type session was closed "..)

So I am forced to work with each fetch eager every time to elimenate this error. I think my work is not good

they told me that spring does not allow Lazy mode, and if I want to work with lazy fashion must add (listener or filter) in the web.xml. Is this true?

Can you give me an example using eager loading?

4

1 回答 1

1

所以。要在视图中获取“惰性”数据,您可以添加到应用程序上下文特殊拦截器:

<mvc:interceptors>
    <bean
        class="org.springframework.orm.hibernate4.support.OpenSessionInViewInterceptor">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
</mvc:interceptors>

或者如果你不害怕你可以entityManagerFactory通过添加新属性来修改:

<property name="jpaProperties">
    <props>
        <prop key="hibernate.enable_lazy_load_no_trans">true</prop>
    </props>
</property>

但不推荐,因为它仍然充满错误

于 2013-05-10T15:54:35.400 回答