Giter VIP home page Giter VIP logo

Comments (25)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
This is a known limitation of batch execution.  Furthermore, because generated 
keys need to be stored in the parameter object, there's no place to store 
multiple keys.  I'm sure we could think of something, but this would be a 
feature request and probably would never see the light of day given the 
awkwardness it would add to the API (even if a list of keys was returned, how 
would they be mapped to the resulting objects?).   I'm open to recommendations 
though. 

Original comment by [email protected] on 11 Jun 2010 at 7:54

  • Added labels: Type-Feature, Version-Release3.x, Component-SqlMaps
  • Removed labels: Type-Defect

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Hello. I want to make multiple row insert, but I don't know how can I retrieve 
all generated keys. Insert statement:
<insert id="copy" useGeneratedKeys="true" keyProperty="clone.clonedId" 
parameterType="map">
    INSERT INTO objects (parameters, owner_id)  SELECT parameters, #{newOwnerId} FROM objects WHERE id IN
    <foreach collection="clones" item="clone" open="(" separator="," close=")">
    #{clone.sourceId}
    </foreach>
</insert>

The clones structure is list of CloneParameter class:

public class CloneParameter {
    @SuppressWarnings({"UnusedDeclaration"})
    private Integer clonedId;
    private final Integer sourceId;

    public CloneParameter(Integer sourceId) {
        Assert.notNull(sourceId);
        this.sourceId = sourceId;
    }

    public Integer getClonedId() {
        return clonedId;
    }

    public Integer getSourceId() {
        return sourceId;
    }
}

Original comment by [email protected] on 12 Aug 2011 at 10:00

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Found mysql-specific answer:
http://stackoverflow.com/questions/5054240/mysql-mulitple-row-insert-select-stat
ement-with-last-insert-id

Original comment by [email protected] on 12 Aug 2011 at 10:50

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Issue 341 has been merged into this issue.

Original comment by eduardo.macarron on 27 Jan 2012 at 5:37

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Can any one test the snapshot? I did a change in r4613 to fix this issue but 
unfortunately neither hsqldb nor derby like generating keys with batches.

Thanks in advance!

Original comment by eduardo.macarron on 28 Jan 2012 at 10:52

  • Changed state: Accepted

Attachments:

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
[deleted comment]

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
[deleted comment]

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
[deleted comment]

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
[deleted comment]

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Workaround we've used is broken after update to 3.1.0. Statement and class 
we've used is attached. In previous versions setClonedId was called 1 time per 
inserted row. Now it's called only one time per batch statement.

Original comment by [email protected] on 13 Mar 2012 at 11:12

Attachments:

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Dirty fix for this issue. Basically it's the same functionality as it was 
before. 
I liked previous non-working version :)

Original comment by [email protected] on 13 Mar 2012 at 11:39

Attachments:

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Alex. Thanks for the report. Can you please open a new issue for this?

Original comment by eduardo.macarron on 14 Mar 2012 at 2:36

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
After having a deeper look I am wondering if you need a workaround. Have you 
tried removing the cloneid stuff and accessing directly to creatorId or 
whatever the generated parameter is?

Original comment by eduardo.macarron on 14 Mar 2012 at 2:42

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Actually generated parameter is clonedId. The problem is that it's set only 1 
time, instead of N, where N is number of inserts

Original comment by [email protected] on 14 Mar 2012 at 8:26

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Do we still need to create another issue?

Original comment by [email protected] on 14 Mar 2012 at 2:25

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Yes please. I think issue #33 is fixed. In your case you are requesting to 
JDBC3 support this sentence:

INSERT INTO TABLE values ('Value1'),('Value2'),('Value3')

For the time being, it should work batching the inserts "in the classic way". I 
mean

INSERT INTO TABLE values ('Value1')
INSERT INTO TABLE values ('Value2')
INSERT INTO TABLE values ('Value3')

And I suppose the performance will be similar, given that statements are 
batched.

Could you try that?

Original comment by eduardo.macarron on 14 Mar 2012 at 2:41

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Created issue 543 to move conversation there

Original comment by [email protected] on 14 Mar 2012 at 6:10

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
    In your case you are requesting to JDBC3 support this sentence:

    INSERT INTO TABLE values ('Value1'),('Value2'),('Value3')

    For the time being, it should work batching the inserts "in the classic way". I mean

    INSERT INTO TABLE values ('Value1')
    INSERT INTO TABLE values ('Value2')
    INSERT INTO TABLE values ('Value3')

    And I suppose the performance will be similar, given that statements are batched.

    Could you try that?

I can try, but I don't want to enable batching for all mappers. Can I do for 1 
statement only?

Original comment by [email protected] on 14 Mar 2012 at 6:14

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
I suppose that. Is is a session parameter so you can create a session, execute 
that statement and close it. 

Original comment by eduardo.macarron on 14 Mar 2012 at 6:26

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
[deleted comment]

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
[deleted comment]

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
For the record I stumbled across a similar issue that is not due to MyBatis, 
but due to the driver.

H2 JDBC driver doesn't return all the generated keys, only the last one. See : 
https://groups.google.com/forum/?fromgroups=#!topic/h2-database/hoM_bQPMvq0

That means you cannot batch insert entities that have relations in a batch mode 
using H2 ! MyBatis or not. And even worse, depending on your mapping choices 
and java orchestration, you can end up with entities that are associated to the 
wrong records, as only the last generated key is returned mybatis will use this 
value on the first item in the list.

However looking at the MySQL Jdbc driver this 'feature' is supported since 
years. Other JDBC drivers might as well.

Original comment by [email protected] on 21 Dec 2012 at 10:45

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Hi Team,

Can you please let me know in which version of mybatis this is fixed.

I want a similar functionality where in I want to do batch execution and set 
the generated keys in to object.

Thanks,
Sravanthi


Original comment by [email protected] on 21 Mar 2014 at 9:27

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
Hi. This one was marked as fixed in 3.1.0. So you can use anyone from it to the 
latest 3.2.5.

Original comment by eduardo.macarron on 21 Mar 2014 at 10:06

from mybatis.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 24, 2024
hi
so now i can do it like [#10 [email protected]] recommend ?

Original comment by [email protected] on 21 Mar 2014 at 5:40

from mybatis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.