I have database record Cat(id='1', name='Unchanged name') and following code:
Code:
Session firstThreadSession = Config.getInstance().getSessionFactory().openSession();
firstThreadSession.get(Cat.class, "1");
//execute in another thread
Session secondThreadSession = Config.getInstance().getSessionFactory().openSession();
Transaction tx = secondThreadSession.beginTransaction();
Cat c = (Cat)secondThreadSession.get(Cat.class, "1");
c.setName("Changed name");
secondThreadSession.update(c);
tx.commit();
////////
System.out.println(((Cat)firstThreadSession.get(Cat.class, "1")).getName());
As result I see "Unchanged name". When I call firstThreadSession.clear() before System.out.println result is correct ('Changed name') .
Is there any way to get actual instance without using firstThreadSession.clear() ?