Hi Parche,
every persistent collection has a internal reference to a hibernate session
which corresponds to the session in which the owner entity was read.
If that session is already closed when you initialize the collection, then the LazyInitializationException raises.
In you code you seem to assume, that the collections should use something like SessionFactory().getCurrentSession
for initializations but that isn't the case.
You must force the collections to use your session, instead to the memorized one, like following:
Code:
SessionFactory sessionf=getHibernateTemplate().getSessionFactory();
Session s =sessionf.openSession();
for(Object coleccion: colecciones){
((PersistentCollection) coleccion).setCurrentSession(s);
Hibernate.initialize(coleccion);
}
session.close();
This works fine for read-only purposes. Changes to your collections will not be persisted to database.