-->
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.  [ 4 posts ] 
Author Message
 Post subject: even after tx.rollback() ; record gets inserted into Databas
PostPosted: Sun Jun 03, 2007 12:08 am 
Newbie

Joined: Sat Apr 21, 2007 9:48 pm
Posts: 9
In my following small test class :

Session sess = new Configuration().configure("conf/hibernate.cfg.xml").buildSessionFactory().getCurrentSession();
Transaction tx = sess.beginTransaction();
System.out.println(sess.connection().getAutoCommit());
Country count = new Country ("abc", 788, "abc");
sess.save (count);
System.out.println(tx.wasRolledBack());
tx.rollback();
System.out.println(tx.wasRolledBack());

I get following output
false
false
true

which shows that tx was rolledback; but when I check DB the record is inserted there .. !!


For reference: hibernate.config.xml is
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/sdl</property>
<property name="connection.username">admin</property>
<property name="connection.password">***********</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">false</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="conf/Country.hbm.xml"/>
</session-factory>


I have 8 yrs of experience but i never faced such weird problem ..
any help is highly appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 03, 2007 5:25 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
I would think the rollback would rollback the last commit. Since there wasn't a commit yet the rollback does nothing.

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 4:58 pm 
Beginner
Beginner

Joined: Mon May 21, 2007 5:22 pm
Posts: 27
Location: Salt Lake City
Hi, I am not getting the any error might be some configuration issue.
Tried with the same example you've posted.
It just rollback the data.

Otherwise check with your database settings :)

_________________
Try 'N' Enjoy !!
Rahul

If helpful do rating ....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 5:35 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
I wthdraw my earlier response. The record should not have been persisted.

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.