In my non-web Hibernate project:
Code:
public class ImageSet {
private Set<GeneralImage> referencedImages;
}
ImageSet imageSet = getImageSet("SeriesID");
Set<GeneralImage> images = imageSet.getReferencedImages();
In hibernate configuration file, set lazy="true" and will meet exception: "LazyInitializationException"
Because in getImageSet method, close the session
Code:
public static ImageSet getImageSet(String UID){
Session session = HibernateUtil.getSessionFactory().openSession();
ImageSet imageSet = findImageSet(UID, session);
session.close();
return imageSet;
}
If I set lazy="false", and it will don't show exception, but I want to set lazy="ture", because of performance. I want to separate Dao layer and application layer, and don't want to let hibernate session appears in application layer, so I want to know how to solve this problem? Thanks!