-->
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.  [ 1 post ] 
Author Message
 Post subject: setAutocommit ignored
PostPosted: Thu Feb 07, 2013 2:17 pm 
Newbie

Joined: Thu Aug 16, 2012 2:09 pm
Posts: 1
I am using Hibernate with Sql Server 2008. I am using setAutoCommit to set a transaction but it is ignored. Here's the data source.
<data-source
class="com.evermind.sql.DriverManagerDataSource"
name="db"
location="jdbc/db"
xa-location="jdbc/xa/db"
ejb-location="jdbc/db"
connection-driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
username="user"
password="pass"
url="jdbc:sqlserver://server:1433;databaseName=db;SelectMethod=cursor"
inactivity-timeout="30"
/>

Here's the code

Boolean saveAutoCommit = sess.connection().getAutoCommit();
sess.connection.setAutoCommit(false);
Transaction tx = sess.beginTransaction();
try {
// do stuff
tx.commit();
catch(Exception ex) {
log.error("exception", ex);
tx.rollback();
} finally {
sess.connection.setAutomCommit(saveAutoCommit);
}

So I force a failure in the "do stuff". The stuff done before the failure shows up in the db which is not expected. In addition the rollback gives an error saying you cannot rollback when autoCommit is true.

I ran a debugger and getAutoCommt() returns false after the set and on every line up to the rollback. After the rollback (and before the finally section) it changes to true on its own.


I've seen other posts on this problem but have not seen a resolution. Any help would be appreciated.

ben


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

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.