hi, im trying to get transactions to work but either I missed something very important in the docs or I dont know whats going on..
anyways heres the code im trying to run, i was expecting an ObjectNotFoundException to be thrown when trying to load the object at the end but its not happening, please help!
Session session = HibernateSession.currentSession();
session.setFlushMode(FlushMode.COMMIT);
Long userId = null;
Transaction tx = null;
try {
tx = session.beginTransaction();
User u = new User();
u.setName("testtx");
u.setPassword("testpassword");
session.save(u);
userId = u.getId();
System.out.println("User u: " + u);
tx.rollback();
} catch (Exception e) {
e.printStackTrace();
}
User ru = (User) session.load(User.class, userId); // shouldnt a ObjectNotFoundException be thrown here?
System.out.println("User ru: " + ru);
HibernateSession.closeSession();
this is the output:
User u: test.model.User@e22f2b[id=524289]
User ru: test.model.User@e22f2b[id=524289]
|