Hi,
Is what I'm doing correct? basically, I start a transaction, obtain a list of objects, close the session then:
1) I can loop true the list, I assume these are detached objects, they are still accessible
2) I open a new Session and Transaction, then set some properties on the objects in the list obtained from old instance of Session, and use new Session to update, it still works, Am I doing correctly?
Thanks,
Angelo
Transaction tx;
Session session;
session = sessionSource.create();
tx = session.beginTransaction();
Query q = session.createQuery("from Transit");
List lst = q.list();
tx.commit();
session.close();
// accessing detached objects
for (Object o : lst) {
Transit tf = (Transit) o;
}
session = sessionSource.create();
tx = session.beginTransaction();
for (Object o : lst) {
Transit tf = (Transit) o;
tf.setCount(100);
session.update(tf); // why I can update a detached object
}
tx.commit();
session.close();
|