You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Comcast Mail <pr...@comcast.net> on 2008/11/21 19:03:58 UTC

Beginner question on transactions...

Hi.

I have code that does the following:

try {
DaoManager.startTransaction();
// loop and do some inserts
...
DaoManager.commitTransaction();
} catch ( Exception ex ) {
  ...
} finally {
  DaoManager.endTransaction();
}


One of the insert fails but the previous inserts have been committed. 
Although the commitTransaction is never reached.

here is my transaction block from sqlmapconfig.xml ( pointing to mysql 
database )...

<transactionManager type="JDBC" commitRequired="true">

<dataSource type="SIMPLE">

<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>

<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost/test"/>

<property name="JDBC.Username" value="..."/>

<property name="JDBC.Password" value="..."/>

<property name="DefaultAutoCommit" value="false"/>

<property name="SetAutoCommitAllowed" value="false"/>

</dataSource>

</transactionManager>



Any ideas. Help appreciated.



Thanks



-- pady


RE: Beginner question on transactions...

Posted by Poitras Christian <Ch...@ircm.qc.ca>.
If it's a new project, I recommend using Spring DAO since iBATIS DAO is deprecated.

See http://ibatis.apache.org/javadownloads.cgi

Christian


-----Original Message-----
From: Comcast Mail [mailto:prabha_pady@comcast.net]
Sent: Saturday, November 22, 2008 7:03 AM
To: user-java@ibatis.apache.org
Subject: Re: Beginner question on transactions...


Hi,

I figured out the issue. It was a combination of setting the SetAutoCommitAllowed, DefaultCommitAllowed properties correctly. Also I had assumed that DaoManagerBuilder.buildDaoManager will return the same instance of Daomanager always ( like a singleton ). So I was creating the dao in my constructor, then for the transaction, building another daomanager. That turned out not tobe true. Once I used the same instance of daomanager, things worked fine.

Thx

-- pady


----- Original Message -----
From: "Comcast Mail" <pr...@comcast.net>
To: <us...@ibatis.apache.org>
Sent: Friday, November 21, 2008 1:35 PM
Subject: Re: Beginner question on transactions...


>
> The tables were created with Engine=InnoDB
>
> mysql 5.0.27
>
> Thx
>
> -- pady
>
>
>
> ----- Original Message -----
> From: "Poitras Christian" <Ch...@ircm.qc.ca>
> To: <us...@ibatis.apache.org>
> Sent: Friday, November 21, 2008 1:12 PM
> Subject: RE: Beginner question on transactions...
>
>
> Are your tables in InnoDB or MyISAM?
>
> InnoDB tables are required in MySQL to support transactions.
>
> Christian
>
> -----Original Message-----
> From: Comcast Mail [mailto:prabha_pady@comcast.net]
> Sent: Friday, November 21, 2008 1:04 PM
> To: user-java@ibatis.apache.org
> Subject: Beginner question on transactions...
>
>
> Hi.
>
> I have code that does the following:
>
> try {
> DaoManager.startTransaction();
> // loop and do some inserts
> ...
> DaoManager.commitTransaction();
> } catch ( Exception ex ) {
>  ...
> } finally {
>  DaoManager.endTransaction();
> }
>
>
> One of the insert fails but the previous inserts have been committed.
> Although the commitTransaction is never reached.
>
> here is my transaction block from sqlmapconfig.xml ( pointing to mysql
> database )...
>
> <transactionManager type="JDBC" commitRequired="true">
>
> <dataSource type="SIMPLE">
>
> <property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
>
> <property name="JDBC.ConnectionURL"
> value="jdbc:mysql://localhost/test"/>
>
> <property name="JDBC.Username" value="..."/>
>
> <property name="JDBC.Password" value="..."/>
>
> <property name="DefaultAutoCommit" value="false"/>
>
> <property name="SetAutoCommitAllowed" value="false"/>
>
> </dataSource>
>
> </transactionManager>
>
>
>
> Any ideas. Help appreciated.
>
>
>
> Thanks
>
>
>
> -- pady
>


Re: Beginner question on transactions...

Posted by Comcast Mail <pr...@comcast.net>.
Hi,

I figured out the issue. It was a combination of setting the 
SetAutoCommitAllowed, DefaultCommitAllowed properties correctly. Also I had 
assumed that DaoManagerBuilder.buildDaoManager will return the same instance 
of Daomanager always ( like a singleton ). So I was creating the dao in my 
constructor, then for the transaction, building another daomanager. That 
turned out not tobe true. Once I used the same instance of daomanager, 
things worked fine.

Thx

-- pady


----- Original Message ----- 
From: "Comcast Mail" <pr...@comcast.net>
To: <us...@ibatis.apache.org>
Sent: Friday, November 21, 2008 1:35 PM
Subject: Re: Beginner question on transactions...


>
> The tables were created with Engine=InnoDB
>
> mysql 5.0.27
>
> Thx
>
> -- pady
>
>
>
> ----- Original Message ----- 
> From: "Poitras Christian" <Ch...@ircm.qc.ca>
> To: <us...@ibatis.apache.org>
> Sent: Friday, November 21, 2008 1:12 PM
> Subject: RE: Beginner question on transactions...
>
>
> Are your tables in InnoDB or MyISAM?
>
> InnoDB tables are required in MySQL to support transactions.
>
> Christian
>
> -----Original Message-----
> From: Comcast Mail [mailto:prabha_pady@comcast.net]
> Sent: Friday, November 21, 2008 1:04 PM
> To: user-java@ibatis.apache.org
> Subject: Beginner question on transactions...
>
>
> Hi.
>
> I have code that does the following:
>
> try {
> DaoManager.startTransaction();
> // loop and do some inserts
> ...
> DaoManager.commitTransaction();
> } catch ( Exception ex ) {
>  ...
> } finally {
>  DaoManager.endTransaction();
> }
>
>
> One of the insert fails but the previous inserts have been committed.
> Although the commitTransaction is never reached.
>
> here is my transaction block from sqlmapconfig.xml ( pointing to mysql 
> database )...
>
> <transactionManager type="JDBC" commitRequired="true">
>
> <dataSource type="SIMPLE">
>
> <property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
>
> <property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost/test"/>
>
> <property name="JDBC.Username" value="..."/>
>
> <property name="JDBC.Password" value="..."/>
>
> <property name="DefaultAutoCommit" value="false"/>
>
> <property name="SetAutoCommitAllowed" value="false"/>
>
> </dataSource>
>
> </transactionManager>
>
>
>
> Any ideas. Help appreciated.
>
>
>
> Thanks
>
>
>
> -- pady
> 


Re: Beginner question on transactions...

Posted by Comcast Mail <pr...@comcast.net>.
The tables were created with Engine=InnoDB

mysql 5.0.27

Thx

-- pady



----- Original Message ----- 
From: "Poitras Christian" <Ch...@ircm.qc.ca>
To: <us...@ibatis.apache.org>
Sent: Friday, November 21, 2008 1:12 PM
Subject: RE: Beginner question on transactions...


Are your tables in InnoDB or MyISAM?

InnoDB tables are required in MySQL to support transactions.

Christian

-----Original Message-----
From: Comcast Mail [mailto:prabha_pady@comcast.net]
Sent: Friday, November 21, 2008 1:04 PM
To: user-java@ibatis.apache.org
Subject: Beginner question on transactions...


Hi.

I have code that does the following:

try {
DaoManager.startTransaction();
// loop and do some inserts
...
DaoManager.commitTransaction();
} catch ( Exception ex ) {
  ...
} finally {
  DaoManager.endTransaction();
}


One of the insert fails but the previous inserts have been committed.
Although the commitTransaction is never reached.

here is my transaction block from sqlmapconfig.xml ( pointing to mysql 
database )...

<transactionManager type="JDBC" commitRequired="true">

<dataSource type="SIMPLE">

<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>

<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost/test"/>

<property name="JDBC.Username" value="..."/>

<property name="JDBC.Password" value="..."/>

<property name="DefaultAutoCommit" value="false"/>

<property name="SetAutoCommitAllowed" value="false"/>

</dataSource>

</transactionManager>



Any ideas. Help appreciated.



Thanks



-- pady


RE: Beginner question on transactions...

Posted by Poitras Christian <Ch...@ircm.qc.ca>.
Are your tables in InnoDB or MyISAM?

InnoDB tables are required in MySQL to support transactions.

Christian

-----Original Message-----
From: Comcast Mail [mailto:prabha_pady@comcast.net]
Sent: Friday, November 21, 2008 1:04 PM
To: user-java@ibatis.apache.org
Subject: Beginner question on transactions...


Hi.

I have code that does the following:

try {
DaoManager.startTransaction();
// loop and do some inserts
...
DaoManager.commitTransaction();
} catch ( Exception ex ) {
  ...
} finally {
  DaoManager.endTransaction();
}


One of the insert fails but the previous inserts have been committed.
Although the commitTransaction is never reached.

here is my transaction block from sqlmapconfig.xml ( pointing to mysql database )...

<transactionManager type="JDBC" commitRequired="true">

<dataSource type="SIMPLE">

<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>

<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost/test"/>

<property name="JDBC.Username" value="..."/>

<property name="JDBC.Password" value="..."/>

<property name="DefaultAutoCommit" value="false"/>

<property name="SetAutoCommitAllowed" value="false"/>

</dataSource>

</transactionManager>



Any ideas. Help appreciated.



Thanks



-- pady