-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: session.save() changes a database without commit?
PostPosted: Wed Jun 22, 2005 9:49 am 
Newbie

Joined: Mon Jun 20, 2005 10:24 pm
Posts: 5
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 22, 2005 10:02 am 
Regular
Regular

Joined: Thu Apr 21, 2005 9:05 am
Posts: 50
Location: Boston, U.S
Make sure that you have not set the setAutoCommit attribute to true
in you hibernate configuration file.

I suspect that it has been set it to true.


Top
 Profile  
 
 Post subject: It's false.
PostPosted: Wed Jun 22, 2005 10:20 am 
Newbie

Joined: Mon Jun 20, 2005 10:24 pm
Posts: 5
I'm printing that attibute and it is false:

16644 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
16645 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - [b]autocommit mode: false[/b]
16650 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://192.168.1.192:3306/neuron
166


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 22, 2005 10:36 am 
Beginner
Beginner

Joined: Mon Aug 16, 2004 6:15 am
Posts: 24
It is my understanding that tables under MYSQL need to be InnoDB to enable transactional support, were your tables created like that?


Top
 Profile  
 
 Post subject: I don't know
PostPosted: Wed Jun 22, 2005 10:45 am 
Newbie

Joined: Mon Jun 20, 2005 10:24 pm
Posts: 5
Let me see. I thought my mysql version supports Innodb... but let me check that.


Top
 Profile  
 
 Post subject: tables in my sql must be in innodb
PostPosted: Wed Jun 22, 2005 6:41 pm 
Newbie

Joined: Mon Jun 20, 2005 10:24 pm
Posts: 5
thank you very much, mahikty.

I change my tables from isam to innodb and it worked ok.

see you.

Luis


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.