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
|
|