I'm developing a web application under JSF 2.0 + Hibernate as ORM. I was tired of having problems everytime I had to load a lazy collection so I found an approach which consists on load the collection in its getter method into my POJO classes class by means of a DAO class if this is an instance of the PersistentBag class.
Basically is something like:
public List<Entity> getLazyCollection()
{
if (this.lazyCollection instanceof PersistentBag)
{
this.lazyCollection = EntityDAO.findById(this.id);
}
return this.lazyCollection;
}
How right/wrong is this approach in your opinion? Thank you.
Edit: I didn't make myself clear. The load is done in my POJO classes, not into the JSF Beans.