I have a detached object.
I make changes to the detached object.
I then reattach the object using session.lock(LockMode.NONE)
I then call session.isDirty() and expect to get a "true" result but I get "false" even though the object is dirty.
Once I have the session open and then make changes to the object, I can call isDirty and get a "true" result.
What am I doing wrong?
Here is an example along with output:
try{
UserInfoFactory.getInstance().initialize(new TestUserInfoObject());
InterfaceDAO inf = new InterfaceDAO();
BigInteger bi = new BigInteger("52538");
List l = inf.findByInterfaceHeaderId(bi);
InterfaceEntry e = (InterfaceEntry)l.get(0);
System.out.println("e.assyPartNum is initially = " + e.getAssyPartNum());
e.setAssyPartNum("test1");
System.out.println("e.assyPartNum is now = " + e.getAssyPartNum());
Session s = HibernateHelper.openSession();
s.lock(e,LockMode.NONE);
System.out.println("Is dirty (it should be true)? " + s.isDirty());
e.setAssyPartNum("test2");
System.out.println("e.assyPartNum is now = " + e.getAssyPartNum());
System.out.println("Is dirty? " + s.isDirty());
HibernateHelper.closeSession();
}catch(Exception ex){
ex.printStackTrace();
}
OUTPUT
===============================================
e.assyPartNum is initially = d
e.assyPartNum is now = test1
Is dirty (it should be true)? false
e.assyPartNum is now = test2
Is dirty? true
|