Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Does anyone know why the instruction session.save() makes changes in a database without commit?
My source code is:
session = factory.openSession();
session.setFlushMode(FlushMode.COMMIT);
transaccion = session.beginTransaction();
session.saveOrUpdate(salida);
transaccion.rollback();
I supposed this piece of code should not take effect in my database, but it does.
The code above is only the isolated problem. Obviously my application is more complex. But please tell me, that code must change my database? if the answer is yes, please tell me where I can find documentation related. If the answer is no, please help me..
regards.
P.S. I followed the example that appears in "Hibernate in action" at 4.2.1 It's some like this:
User user = new User();
user.getName().setFirstName("Juan");
user.getName().setLastName("Perez");
Session session = sessions.openSession();
Transaction transaction = transaction.beginTransaction();
session.save(user);
transaction.commit;
session.close();
In the hibernate in action book, It says that, if an exception ocurrs, then the transaction could be rolled back with the following code:
try{
User user = new User();
user.getName().setFirstName("Juan");
user.getName().setLastName("Perez");
Session session = sessions.openSession();
Transaction transaction = transaction.beginTransaction();
session.save(user);
transaction.commit;
session.close();
}catch(HibernateException e){
transaction.rollback();
.....
}
Well, I followed the example step by step, ant I forced an exception, but the roll back didn't take effect. Then, I put the rollback instruction explicitly but my database still changing:
User user = new User();
user.getName().setFirstName("Juan");
user.getName().setLastName("Perez");
Session session = sessions.openSession();
Transaction transaction = transaction.beginTransaction();
session.save(user);
transaction.rollback();///////////////////////////////////////////explicit rollback
session.close();
Please, I need help. The real problem is that, if I can't rollback the session.save() instruction, then i need to implement my own methods of deleting tables when an exception occurs. Is it correct?
Regards again.