• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ibatis : how to set AutoCommit mode to false

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am newbie to this forum, in case I post a wrong topic here, please kindly let me know.

We have some applications using ibatis to run database queries in JDBC, but when we upgrade
to SQL Server JDBC 3.0, we encounter this error when SQL Server statements raise excetpion.

com.ibatis.dao.client.DaoException: Error ending JDBC transaction. Cause: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot invoke a rollback operation when the AutoCommit mode is set to "true".

I think the old JDBC driver does not handle this or now the new JDBC driver does not allow this type of settings.

Do any expert here know if I can disable autocommit mode from ibatis config file?

I really need your advice on fixing this.

Thanks in advance,
Ray
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at the myBatis documentation if you are providing your own Connection you can set it there. I also see this constructor on SqlSession


Read that here:
http://www.mybatis.org/core/java-api.html
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see you are using ibatis not mybatis. Just an FYI ibatis is no longer supported. Try to set that property on your datasource wherever it is configured.

From the documentation:


<transactionManager type="JDBC">
<property name="DataSource" value="DBCP"/>
<property name="JDBC.Driver" value="${driver}"/>
<property name="JDBC.ConnectionURL" value="${url}"/>
<property name="JDBC.Username" value="${username}"/>
<property name="JDBC.Password" value="${password}"/>
<property name="JDBC.DefaultAutoCommit" value="false" />
<!-- The following are optional -->
<property name="Pool.MaximumActiveConnections" value="10"/>
<property name="Pool.MaximumIdleConnections" value="5"/>
<property name="Pool.MaximumWait" value="60000"/>
<!-- Use of the validation query can be problematic. If you have difficulty, try without it. -->
<property name="Pool.ValidationQuery" value="select 1 from ACCOUNT"/>
<property name="Pool.LogAbandoned" value="false"/>
<property name="Pool.RemoveAbandoned" value="false"/>
<property name="Pool.RemoveAbandonedTimeout" value="50000"/>
</transactionManager>
 
Rlee Lee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bill Gorder wrote:I see you are using ibatis not mybatis. Just an FYI ibatis is no longer supported. Try to set that property on your datasource wherever it is configured.

From the documentation:


<transactionManager type="JDBC">
<property name="DataSource" value="DBCP"/>
<property name="JDBC.Driver" value="${driver}"/>
<property name="JDBC.ConnectionURL" value="${url}"/>
<property name="JDBC.Username" value="${username}"/>
<property name="JDBC.Password" value="${password}"/>
<property name="JDBC.DefaultAutoCommit" value="false" />
<!-- The following are optional -->
<property name="Pool.MaximumActiveConnections" value="10"/>
<property name="Pool.MaximumIdleConnections" value="5"/>
<property name="Pool.MaximumWait" value="60000"/>
<!-- Use of the validation query can be problematic. If you have difficulty, try without it. -->
<property name="Pool.ValidationQuery" value="select 1 from ACCOUNT"/>
<property name="Pool.LogAbandoned" value="false"/>
<property name="Pool.RemoveAbandoned" value="false"/>
<property name="Pool.RemoveAbandonedTimeout" value="50000"/>
</transactionManager>



Hi Bill,

Really to happy to see your reply, I guess no one is using iBatis now. Actually, I am not good in using it but my team likes to use this.

May I ask your help again? I have two questions hope you can help to answer,

(1) Can Spring replace iBatis without any code changes?
(2) Suppose our dao.xml config like this

<daoConfig>

<context>
<transactionManager type="JDBC">
<property name="DataSource" value="JNDI"/>
<property name="DBJndiContext" value="java:comp/env/jdbc/ds-mssql"/>
</transactionManager>
<dao interface="com.test.DownloadDaoIF" implementation="com.test.DownloadDaoJdbc" />
</context>

Is it possible I put "<property name="JDBC.DefaultAutoCommit" value="false" />" in the dao.xml to control the JDBC driver to set
AutoCommit mode to false?

Really thanks for your help and advice,
Ray
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For microsoft databases I believe you need to set autoCommit="false" property on the datasource. You are doing a JNDI lookup for the datasource so add that property to wherever you have the datasource defined. for Tomcat that would be in your Context.xml in Websphere you would do it from the Admin console etc.

 
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic