• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot invoke a rollback operation when the AutoCommit mode is set to "true"

 
Arpit Aggarwal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using ScriptRunner class For running SQL scripts For SQL SERVER 2005 Data base. It is giving me following error for insertion queries other queries for deletion or selection is working fine.

com.microsoft.sqlserver.jdbc.SQLServerException: Cannot invoke a rollback operation when the AutoCommit mode is set to "true".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.rollback(Unknown Source)
at com.ibatis.common.jdbc.ScriptRunner.runScript(ScriptRunner.java:222)
at com.ibatis.common.jdbc.ScriptRunner.runScript(ScriptRunner.java:114)

Please help what can be the issue.

Thanks

Arpit
 
Campbell Ritchie
Sheriff
Posts: 51456
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you can't rollback when autocommit is on. If you need rollback, you must turn autocommit off. Or use a transaction, which is a posh way of turning autocommit off.
 
Arpit Aggarwal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell, I tried with some <prop key="hibernate.connection.autocommit">false</prop> for doing auto commit false from my spring application context file. As well as tried to off auto commit of Database SQL SERVER 2005 by using command SET IMPLICIT_TRANSACTIONS { ON } but it is giving same error to me.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arpit Aggarwal wrote:Thanks Campbell, I tried with some <prop key="hibernate.connection.autocommit">false</prop> for doing auto commit false from my spring application context file. As well as tried to off auto commit of Database SQL SERVER 2005 by using command SET IMPLICIT_TRANSACTIONS { ON } but it is giving same error to me.


Don't you pass the autocommit property as a parameter in ScriptRunner's constructor?
 
Arpit Aggarwal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, I was pasing wrong parameter in ScriptRunner's constructor once i changed:

scriptRunner = new ScriptRunner(con, true, true);

To

scriptRunner = new ScriptRunner(con, false, true);

Its working fine for me

Thanks a lot for your help Paul, Campbell.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
Campbell Ritchie
Sheriff
Posts: 51456
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:You are welcome
Agreed
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic