I'm having trouble with rollbacks not getting rolled back. I'm using hibernate3 with mysql. I have a simple table, call Person, it only has one column, which is the person's name. This is the stripped down version of the code Im using:
Code:
SessionFactory factory = HibernateConfiguration.getSessionFactory();
Session session = factory.openSession();
session.beginTransaction();
Person p1 = new Person();
Person p2 = new Person();
Person p3 = new Person();
p1.setName("Bill");
p2.setName("Hank");
p3.setName("Dale");
session.save(p1);
session.save(p2);
session.save(p3);
session.getTransaction().commit();
session.close();
System.out.println("BREAKPOINT1");
session = factory.openSession();
session.beginTransaction();
session.createQuery("delete from Person").executeUpdate();
session.getTransaction().rollback();
session.close();
System.out.println("BREAKPOINT2");
I run this code through the java debugger, so at breakpoint1, it saves 3 persons to the database, Hank, Bill and Dale. At this time, I manually run a select query on mysql server, and I see the 3 rows, everything looks ok.
The second part of the code deletes all the rows, then changes its mind and does a rollback. But this rollback doesn't work, as the rows in the database gets deleted when this code finishes. Can anyone help me debug this, what's wrong with my code?