I have a situation a bit different of the example below.
Code:
Session session = sessions.openSession();
Transaction tx = session.beginTransaction();
Category cat = (Category) session.get(Category.class, id);
Hibernate.initialize( cat.getItems() );
tx.commit();
session.close();
Iterator iter = cat.getItems().iterator();
In my case, the object that has the lazy association, already was instatieted by one session that was closed. This is my "cat" object. What can I do if the cat object of the example above was already created by another session that was closed?
My code:
Code:
Session session = HibernateUtil.getSession();
Transaction trans = session.beginTransaction();
session.update(tesoura);
Hibernate.initialize(tesoura.getMateriais());
trans.commit();
session.close();
visaoTesoura.getTableModel.setLines(tesoura.getMateriais());