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 Gregg Bolinger <gd...@gmail.com> on 2008/01/03 00:56:56 UTC

Batch Inserts and

If doing a batch insert on several objects I can't seem to retrieve the
auto_increment key using the <selectKey /> tag.  Individual inserts work
just fine.  Is this expected?

Thanks.

Gregg

Re: Batch Inserts and

Posted by Larry Meadors <lm...@apache.org>.
I don't know enough about your data to say for sure, but you might
have an easier time with a stored procedure - if your data is simple
enough.

I've done things like passing in comma delimited lists to stored
procedures - then you can do it all in-process with the database. That
way you can insert or update hundreds of records by making one call to
the database and passing just a few strings.

If you think this sounds feasible in your case, describe your case a
bit more and we'll see what we can do.

Larry


On Jan 2, 2008 9:20 PM, Gregg Bolinger <gd...@gmail.com> wrote:
> Well, it would need to be more like
>
> batch insert 100 parents
> foreach(parent) {
>     batch 100 children (with a parentId which I don't have, hence the
> problem)
> }
>
>
> Gregg
>
>
>
>  On Jan 2, 2008 10:12 PM, Justin Stanczak <ri...@gmail.com> wrote:
> > I'm new so I probably don't know what I'm talking about, but wouldn't it
> be faster to use SQL to create all this and just return a list of parents? I
> guess unless each parent and child needs to be edited. Then Nathan's code is
> the way to go.
> >
> >
> >
> >
> >
> > On Jan 2, 2008 10:02 PM, Nathan Maves <na...@gmail.com> wrote:
> >
> > > we in my dao layer I would have something like...
> > >
> > >
> > > psudeo {
> > >   batch insert the 100 partents
> > >
> > >
> > >   foreach(parent) {
> > >     batch the 100 children;
> > >     collection = queryForList("getChildren",parentId);
> > >
> > >
> > >
> > >   }
> > > }
> > >
> > >
> > > On Jan 2, 2008 5:55 PM, Gregg Bolinger < gdboling.ibatis@gmail.com>
> wrote:
> > >
> > > > Well, the problem is that I need them for a parent child relationship.
> Are there any known solutions?
> > > >
> > > > So say I batch insert 100 parents.  And then I need to batch insert
> 100 children for each parent.  What is the best way to achieve this?
> > > >
> > > > Thanks.
> > > >
> > > > Gregg
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On Jan 2, 2008 6:37 PM, Nathan Maves < nathan.maves@gmail.com> wrote:
> > > >
> > > > > Gregg,
> > > > >
> > > > >
> > > > > The underlyng call is to
> http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch()
> which as you can see from the javadocs only returns the number of effected
> rows.
> > > > >
> > > > >
> > > > > I don't know of any way that would allow you to return the ids for
> each batched insert with the current java.sql api's.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Nathan
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On Jan 2, 2008 4:56 PM, Gregg Bolinger < gdboling.ibatis@gmail.com>
> wrote:
> > > > >
> > > > > > If doing a batch insert on several objects I can't seem to
> retrieve the auto_increment key using the <selectKey /> tag.  Individual
> inserts work just fine.  Is this expected?
> > > > > >
> > > > > > Thanks.
> > > > > >
> > > > > > Gregg
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
> >
> > --
> > "All that is necessary for the triumph of evil is that good men do
> nothing."   Edmund Burke
>
>

Re: Batch Inserts and

Posted by Gregg Bolinger <gd...@gmail.com>.
Well, it would need to be more like

batch insert 100 parents
foreach(parent) {
    batch 100 children (with a parentId which I don't have, hence the
problem)
}


Gregg

On Jan 2, 2008 10:12 PM, Justin Stanczak <ri...@gmail.com> wrote:

> I'm new so I probably don't know what I'm talking about, but wouldn't it
> be faster to use SQL to create all this and just return a list of parents? I
> guess unless each parent and child needs to be edited. Then Nathan's code is
> the way to go.
>
>
> On Jan 2, 2008 10:02 PM, Nathan Maves <na...@gmail.com> wrote:
>
> > we in my dao layer I would have something like...
> > psudeo {
> >   batch insert the 100 partents
> >
> >   foreach(parent) {
> >     batch the 100 children;
> >     collection = queryForList("getChildren",parentId);
> >   }
> > }
> >
> > On Jan 2, 2008 5:55 PM, Gregg Bolinger < gdboling.ibatis@gmail.com>
> > wrote:
> >
> > > Well, the problem is that I need them for a parent child
> > > relationship.  Are there any known solutions?
> > >
> > > So say I batch insert 100 parents.  And then I need to batch insert
> > > 100 children for each parent.  What is the best way to achieve this?
> > >
> > > Thanks.
> > >
> > > Gregg
> > >
> > >
> > > On Jan 2, 2008 6:37 PM, Nathan Maves < nathan.maves@gmail.com> wrote:
> > >
> > > > Gregg,
> > > > The underlyng call is to http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch()
> > > >
> > > > <http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch%28%29>which as you can see from the javadocs only returns the number of effected
> > > > rows.
> > > >
> > > > I don't know of any way that would allow you to return the ids for
> > > > each batched insert with the current java.sql api's.
> > > >
> > > >
> > > > Nathan
> > > >
> > > >
> > > > On Jan 2, 2008 4:56 PM, Gregg Bolinger < gdboling.ibatis@gmail.com>
> > > > wrote:
> > > >
> > > > > If doing a batch insert on several objects I can't seem to
> > > > > retrieve the auto_increment key using the <selectKey /> tag.  Individual
> > > > > inserts work just fine.  Is this expected?
> > > > >
> > > > > Thanks.
> > > > >
> > > > > Gregg
> > > > >
> > > >
> > > >
> > >
> >
>
>
> --
> "All that is necessary for the triumph of evil is that good men do
> nothing."   Edmund Burke

Re: Batch Inserts and

Posted by Justin Stanczak <ri...@gmail.com>.
I'm new so I probably don't know what I'm talking about, but wouldn't it be
faster to use SQL to create all this and just return a list of parents? I
guess unless each parent and child needs to be edited. Then Nathan's code is
the way to go.

On Jan 2, 2008 10:02 PM, Nathan Maves <na...@gmail.com> wrote:

> we in my dao layer I would have something like...
> psudeo {
>   batch insert the 100 partents
>
>   foreach(parent) {
>     batch the 100 children;
>     collection = queryForList("getChildren",parentId);
>   }
> }
>
> On Jan 2, 2008 5:55 PM, Gregg Bolinger < gdboling.ibatis@gmail.com> wrote:
>
> > Well, the problem is that I need them for a parent child relationship.
> > Are there any known solutions?
> >
> > So say I batch insert 100 parents.  And then I need to batch insert 100
> > children for each parent.  What is the best way to achieve this?
> >
> > Thanks.
> >
> > Gregg
> >
> >
> > On Jan 2, 2008 6:37 PM, Nathan Maves < nathan.maves@gmail.com> wrote:
> >
> > > Gregg,
> > > The underlyng call is to http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch()
> > >
> > > <http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch%28%29>which as you can see from the javadocs only returns the number of effected
> > > rows.
> > >
> > > I don't know of any way that would allow you to return the ids for
> > > each batched insert with the current java.sql api's.
> > >
> > >
> > > Nathan
> > >
> > >
> > > On Jan 2, 2008 4:56 PM, Gregg Bolinger < gdboling.ibatis@gmail.com>
> > > wrote:
> > >
> > > > If doing a batch insert on several objects I can't seem to retrieve
> > > > the auto_increment key using the <selectKey /> tag.  Individual inserts work
> > > > just fine.  Is this expected?
> > > >
> > > > Thanks.
> > > >
> > > > Gregg
> > > >
> > >
> > >
> >
>


-- 
"All that is necessary for the triumph of evil is that good men do nothing."
  Edmund Burke

Re: Batch Inserts and

Posted by Nathan Maves <na...@gmail.com>.
we in my dao layer I would have something like...
psudeo {
  batch insert the 100 partents

  foreach(parent) {
    batch the 100 children;
    collection = queryForList("getChildren",parentId);
  }
}

On Jan 2, 2008 5:55 PM, Gregg Bolinger <gd...@gmail.com> wrote:

> Well, the problem is that I need them for a parent child relationship.
> Are there any known solutions?
>
> So say I batch insert 100 parents.  And then I need to batch insert 100
> children for each parent.  What is the best way to achieve this?
>
> Thanks.
>
> Gregg
>
>
> On Jan 2, 2008 6:37 PM, Nathan Maves <na...@gmail.com> wrote:
>
> > Gregg,
> > The underlyng call is to http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch()
> >
> > <http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch%28%29>which as you can see from the javadocs only returns the number of effected
> > rows.
> >
> > I don't know of any way that would allow you to return the ids for each
> > batched insert with the current java.sql api's.
> >
> >
> > Nathan
> >
> >
> > On Jan 2, 2008 4:56 PM, Gregg Bolinger < gdboling.ibatis@gmail.com>
> > wrote:
> >
> > > If doing a batch insert on several objects I can't seem to retrieve
> > > the auto_increment key using the <selectKey /> tag.  Individual inserts work
> > > just fine.  Is this expected?
> > >
> > > Thanks.
> > >
> > > Gregg
> > >
> >
> >
>

Re: Batch Inserts and

Posted by Gregg Bolinger <gd...@gmail.com>.
Well, the problem is that I need them for a parent child relationship.  Are
there any known solutions?

So say I batch insert 100 parents.  And then I need to batch insert 100
children for each parent.  What is the best way to achieve this?

Thanks.

Gregg

On Jan 2, 2008 6:37 PM, Nathan Maves <na...@gmail.com> wrote:

> Gregg,
> The underlyng call is to http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch()
>
> <http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch%28%29>which as you can see from the javadocs only returns the number of effected
> rows.
>
> I don't know of any way that would allow you to return the ids for each
> batched insert with the current java.sql api's.
>
>
> Nathan
>
>
> On Jan 2, 2008 4:56 PM, Gregg Bolinger < gdboling.ibatis@gmail.com> wrote:
>
> > If doing a batch insert on several objects I can't seem to retrieve the
> > auto_increment key using the <selectKey /> tag.  Individual inserts work
> > just fine.  Is this expected?
> >
> > Thanks.
> >
> > Gregg
> >
>
>

Re: Batch Inserts and

Posted by Nathan Maves <na...@gmail.com>.
Gregg,
The underlyng call is to
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch()which
as you can see from the javadocs only returns the number of effected
rows.

I don't know of any way that would allow you to return the ids for each
batched insert with the current java.sql api's.


Nathan

On Jan 2, 2008 4:56 PM, Gregg Bolinger <gd...@gmail.com> wrote:

> If doing a batch insert on several objects I can't seem to retrieve the
> auto_increment key using the <selectKey /> tag.  Individual inserts work
> just fine.  Is this expected?
>
> Thanks.
>
> Gregg
>