Hello, i'm new in Hibernate. I'm trying to figure out how Hibernate suppose to rollback transactions.
Code:
Session session = HibernateUtil.getSession();
session.beginTransaction();
User user = new User();
user.setUserName("userName");
session.save(user);
session.flush();
session.getTransaction().rollback();
session.close();
As i understand the code above should rollback transaction and user would not be created in database. But after executing this code, i can see real changes in database. Even if i comment session.flush() i can see changes in database.
Toggeling rollback/commit in the code below works fine. Commit - make real changes, rollback does not.
Code:
Session session = HibernateUtil.getSession();
session.beginTransaction();
User uu = (User)session.load(User.class, new Long(99));
uu.setUserName("new name");
session.getTransaction().rollback();
session.close();
It's like calling session.save() or session.flush() method commit my transaction automaticity. Is it normal ?
Any help will be highly appreciated