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 Simon Brunner <li...@simonbrunner.com> on 2005/05/03 10:35:42 UTC
Transactions/BatchStatements
List,
we just started a project from scratch and chose Spring/iBatis/Struts to
build a mid-size J2EE web application. First I've to say that I'm very
impressed on how fast you get productive by using iBatis. Everything went
smooth until I wanted to do a batch insert. As we write JUnit testclasses
for the entire app I used my iBatis DAOS without Spring's transaction
demarcation (simply invoked the Dao by a test class). Under that
environment iBatis executed my batch statements as single inserts until I
read these lines in the mailing list archive:
> Clinton Begin
> Wed, 01 Dec 2004 12:00:53 -0800
>> I'm currently using IBatis version 2.0.3. I'm not able to work upon with
>> Batch. I'm
>> doing the following :
>> sqlMap.startBatch();
> Are you starting a the transaction too? So...
> startTransaction()
> startBatch()
> insert...
> update...
> executeBatch()
> commitTransaction()
> endTransaction
Then I added transaction-support to my Spring Dao and it worked. Now I
wonder why the execution of batch updates relys on the start and commit of
a transaction?
Thanks & best regards
Simon
Re: Transactions/BatchStatements
Posted by Brice Ruth <bd...@gmail.com>.
If you're not using startBatch() - then iBATIS will have JDBC run each one
individually ... the batching is something that's driver specific (but
supported by JDBC), if I recall correctly. It just adds some efficiency.
Each of your inserts runs at the time they are called (without batching),
the commit is just a message sent to the database. What *it* does at that
time, is implementation dependent.
If you look at your JDBC traffic, tho - you'll see it executing each insert
when its called, and not waiting for the commit/endTransaction to be called.
On 5/4/05, Gregg D Bolinger <gt...@gmail.com> wrote:
>
> I am curious as to iBatis batching also. I have a question. From
> what you stated below, I am inferring that when you start a
> transaction, all inserts/updates/deletes are batched and then sent on
> commit? Here is my problem. I need to batch updates and inserts to
> multiple tables. So I am doing something like this.
>
> daoManager.startTransaction
> for loop {
> personDAO.insert
> }
> for loop{
> fooDAO.insert
> }
> daoManager.commit
> finally
> daoManager.endTransaction
>
> So are all the inserts for personDAO and fooDAO batched at this point
> automatically?
>
> Gregg
>
>
> On 5/3/05, Simon Brunner <li...@simonbrunner.com> wrote:
> > List,
> >
> > we just started a project from scratch and chose Spring/iBatis/Struts to
> > build a mid-size J2EE web application. First I've to say that I'm very
> > impressed on how fast you get productive by using iBatis. Everything
> went
> > smooth until I wanted to do a batch insert. As we write JUnit
> testclasses
> > for the entire app I used my iBatis DAOS without Spring's transaction
> > demarcation (simply invoked the Dao by a test class). Under that
> > environment iBatis executed my batch statements as single inserts until
> I
> > read these lines in the mailing list archive:
> >
> > > Clinton Begin
> > > Wed, 01 Dec 2004 12:00:53 -0800
> >
> > >> I'm currently using IBatis version 2.0.3. I'm not able to work upon
> with
> > >> Batch. I'm
> > >> doing the following :
> > >> sqlMap.startBatch();
> >
> > > Are you starting a the transaction too? So...
> >
> > > startTransaction()
> > > startBatch()
> > > insert...
> > > update...
> > > executeBatch()
> > > commitTransaction()
> > > endTransaction
> >
> > Then I added transaction-support to my Spring Dao and it worked. Now I
> > wonder why the execution of batch updates relys on the start and commit
> of
> > a transaction?
> >
> > Thanks & best regards
> >
> > Simon
> >
> >
>
--
Brice Ruth
Software Engineer, Madison WI
Re: Transactions/BatchStatements
Posted by Gregg D Bolinger <gt...@gmail.com>.
I am curious as to iBatis batching also. I have a question. From
what you stated below, I am inferring that when you start a
transaction, all inserts/updates/deletes are batched and then sent on
commit? Here is my problem. I need to batch updates and inserts to
multiple tables. So I am doing something like this.
daoManager.startTransaction
for loop {
personDAO.insert
}
for loop{
fooDAO.insert
}
daoManager.commit
finally
daoManager.endTransaction
So are all the inserts for personDAO and fooDAO batched at this point
automatically?
Gregg
On 5/3/05, Simon Brunner <li...@simonbrunner.com> wrote:
> List,
>
> we just started a project from scratch and chose Spring/iBatis/Struts to
> build a mid-size J2EE web application. First I've to say that I'm very
> impressed on how fast you get productive by using iBatis. Everything went
> smooth until I wanted to do a batch insert. As we write JUnit testclasses
> for the entire app I used my iBatis DAOS without Spring's transaction
> demarcation (simply invoked the Dao by a test class). Under that
> environment iBatis executed my batch statements as single inserts until I
> read these lines in the mailing list archive:
>
> > Clinton Begin
> > Wed, 01 Dec 2004 12:00:53 -0800
>
> >> I'm currently using IBatis version 2.0.3. I'm not able to work upon with
> >> Batch. I'm
> >> doing the following :
> >> sqlMap.startBatch();
>
> > Are you starting a the transaction too? So...
>
> > startTransaction()
> > startBatch()
> > insert...
> > update...
> > executeBatch()
> > commitTransaction()
> > endTransaction
>
> Then I added transaction-support to my Spring Dao and it worked. Now I
> wonder why the execution of batch updates relys on the start and commit of
> a transaction?
>
> Thanks & best regards
>
> Simon
>
>
Re: Transactions/BatchStatements
Posted by Brice Ruth <bd...@gmail.com>.
Can you do batch w/ plain JDBC w/o a transaction?
On 5/3/05, Simon Brunner <li...@simonbrunner.com> wrote:
>
> List,
>
> we just started a project from scratch and chose Spring/iBatis/Struts to
> build a mid-size J2EE web application. First I've to say that I'm very
> impressed on how fast you get productive by using iBatis. Everything went
> smooth until I wanted to do a batch insert. As we write JUnit testclasses
> for the entire app I used my iBatis DAOS without Spring's transaction
> demarcation (simply invoked the Dao by a test class). Under that
> environment iBatis executed my batch statements as single inserts until I
> read these lines in the mailing list archive:
>
> > Clinton Begin
> > Wed, 01 Dec 2004 12:00:53 -0800
>
> >> I'm currently using IBatis version 2.0.3. I'm not able to work upon
> with
> >> Batch. I'm
> >> doing the following :
> >> sqlMap.startBatch();
>
> > Are you starting a the transaction too? So...
>
> > startTransaction()
> > startBatch()
> > insert...
> > update...
> > executeBatch()
> > commitTransaction()
> > endTransaction
>
> Then I added transaction-support to my Spring Dao and it worked. Now I
> wonder why the execution of batch updates relys on the start and commit of
> a transaction?
>
> Thanks & best regards
>
> Simon
>
>
--
Brice Ruth
Software Engineer, Madison WI