When trying to get items from db, I got this error:
13:00:13.876 [7838526@qtp-204712603-0] ERROR o.h.LazyInitializationException - failed to lazily initialize a collection of role: bo.myobj, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: de.myob.linkedstuff, no session or session was closed
I understand that with switching to eager instead of lazy loading solves this problem, e.g.
@OneToMany(mappedBy = "myobj", cascade = CascadeType.ALL, fetch=FetchType.EAGER)
and I also understand that eager loading is discouraged. What is the best practitce in order to cope with this issue?
Better separation between the persistence and other layers. Make sure the objects produced by the persistence layer do not include any reference to Hibernate.
The article Hibernate, Get Out of My POJO! may be helpful.