I'm having a lot of trouble working out what is the correct way to do updates in the context of long transactions.
Given the following pseudo code. I would expect that the second saveOrUpdate should throw an exception given that the mapping for class Foo uses a version.
Code:
Foo foo1;
Foo foo2;
s = sessionFactory.openSession();
foo1 s.load(Foo.class, new Integer(1));
s.close();
.. do some work
s = sessionFactory.openSession();
foo2 s.load(Foo.class, new Integer(1));
s.close();
... do some work which modifies foo1
s = sessionFactory.openSession();
s.saveOrUpdate(foo1);
s.close();
... do some work which modifies foo2
s = sessionFactory.openSession();
s.saveOrUpdate(foo2);
s.close();
My first thought was that perhaps I need to reassociate the Foo objects with the session using s.lock(foo, LockMode.READ) but if I do that I get a
Code:
net.sf.hibernate.HibernateException: reassociated object has dirty collection reference
at the first update.
Any advice would be greatly appreciated.
Thanks
Oliver Hutchison