how can I get a lazy object?
for example, I've got a "customer" table and the "request" table then I've build a project using hibernate and JPA.
in the customer table there's a code like this
@OneToMany(cascade = CascadeType.ALL, fetch =FetchType.LAZY , mappedBy = "customer")
public Set<Request> getRequests() {
return this.requests;
}
so, if from the customer object call the getRequests()
method, it's return a empty object because it's lazy.
How can i do to get a lazy object full without use EAGER
annotation?
i've seen that my problems depends on the session, because it is close. So, in the server side I need keep open session by JPA. How can I do it?
this is a part of my applicationContext.xml but it doesn't 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>