how can i get a lazy object?
for example, I have a client table and a query table, then I create a project using sleep mode and JPA.
in the client table there is such a code
@OneToMany(cascade = CascadeType.ALL, fetch =FetchType.LAZY , mappedBy = "customer")
public Set<Request> getRequests() {
return this.requests;
}
therefore, if a method is called from a client object getRequests(), it returns an empty object because it is lazy.
How can I do to get a lazy object without using annotation EAGER?
I saw that my problems depend on the session, because it is close. So, on the server side, I need to keep an open JPA session. How can i do this?
this is part of my applicationContext.xml, but it does not work:
<bean class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitName" value="gestazPU"/>
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="ebOpenEMinView" class="org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager"/>
<bean id="TipoTicketDAO" class="it.stasbranger.gestaz.server.dao.impl.TipoTicketDAOImpl">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
source
share