aspose file tools*
The moose likes Object Relational Mapping and the fly likes ibatis : how to set AutoCommit mode to false Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ibatis : how to set AutoCommit mode to false" Watch "ibatis : how to set AutoCommit mode to false" New topic
Author

ibatis : how to set AutoCommit mode to false

Rlee Lee
Greenhorn

Joined: Sep 21, 2012
Posts: 2
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
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

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


[How To Ask Questions][Read before you PM me]
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

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

Joined: Sep 21, 2012
Posts: 2
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

Joined: Mar 07, 2010
Posts: 1632
    
    7

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.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ibatis : how to set AutoCommit mode to false
 
Similar Threads
Oracle vs SQL Server with J2EE
Auto commit???
Free JDBC driver for SQLServer 7?
Not associated with a trusted SQL Server connection
cannot bind variables to upsert query using preparedstatement