Hibernate version: 3.2.2
Name and version of the database you are using: MySQL 5
I have a problem with refreshing objects.
Code:
Station station = new Station();
station.setName("1");
SessionFactory f = KLTMContext.getSessionFactory("test_hibernate");
s1 = f.openSession();
s2 = f.openSession();
Transaction t = s1.beginTransaction();
s1.saveOrUpdate(station);
t.commit();
Long objectId = new Long(station.getObjectId());
Object o = s2.load(Station.class, objectId);
// load object and change name to 2
o = s1.load(Station.class, objectId);
((Station) o).setName("2");
t = s1.beginTransaction();
s1.saveOrUpdate(o);
t.commit();
// load object and refresh, the name changes from 1 to 2
o = s2.load(Station.class, objectId);
s2.refresh(o);
// load object and change name to 3
o = s1.load(Station.class, objectId);
((Station) o).setName("3");
t = s1.beginTransaction();
s1.saveOrUpdate(o);
t.commit();
// load object and refresh, the name is still 2 after the refresh
o = s2.load(Station.class, objectId);
s2.refresh(o);
// load object and change name to 4
o = s1.load(Station.class, objectId);
((Station) o).setName("4");
t = s1.beginTransaction();
s1.saveOrUpdate(o);
t.commit();
// load object and refresh, the name is still 2 after the refresh
o = s2.load(Station.class, objectId);
s2.refresh(o);
s1.close();
s2.close();
the first session.refresh() of session 2 refreshes the object right, the name of the object changes from "1" to "2", but then all session.refresh() dont refresh the name of the object to "3" or "4".
the sql statemets are always executetd but the object wont change.
So whats the behavior of session.refresh() and how do i use it the right way?