emacarron / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

Return value of BatchExecutor.doUpdate method is Integer.MIN_VALUE + 1002 #96

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the MyBatis are you using?
3.0.1

Please describe the problem.  Unit tests are best!
Return value of BatchExecutor.doUpdate is Integer.MIN_VALUE + 1002

What is the expected output? What do you see instead?
The expected output is that my SqlSession.update(MappedStatement,Object) 
returns the number of rows affected by update. Where SqlSession is created with 
parameter ExecutorType.BATCH.
Instead I see a negative number without any sense.

Please provide any additional information below.
In the class org.apache.ibatis.executor.BatchExecutor, method 
doUpdate(MappedStatement,Object) I can see "return BATCH_UPDATE_RETURN_VALUE" 
where BATCH_UPDATE_RETURN_VALUE = Integer.MIN_VALUE + 1002
I don't think this is the correct behaviour.

Original issue reported on code.google.com by giat...@hotmail.com on 6 Sep 2010 at 1:25

GoogleCodeExporter commented 9 years ago
that's nothing effect!

the value returned of the method doUpdate has no using,the realy result of 
update effect's rows  is  the method doFlushStatements returned!!!

Original comment by kuaiyuel...@gmail.com on 19 Sep 2010 at 6:34

GoogleCodeExporter commented 9 years ago
So, I can't understand how I should use the ExecutorType.BATCH and the 
documentation doesn't help me.
I write the sample code below but it doesn't work properly: it executes the 
doUpdate method of BatchExecutor and returns the strange value described in 
first post, but it works.

Could anybody make an example that return me the number of entries updated?

thanks

SqlSession session = getSession(ExecutorType.BATCH);
List entries = session.selectList("getAllEntries");
int upd = 0;
for (Object object : entries) {
   myObj obj = (myObj) object;
   obj.setColumn(update);
   upd += session.update("updateSingleEntry", obj);
}
return upd;

myObj is:
public class myObj implements Serializable {
    private String key;
    private String value;

    public void setKey(String key) {
        this.key= key;
    }

    public String getKey() {
        return key;
    }

    public void setValue(String value) {
        this.value= value;
    }

    public String getValue() {
        return value;
    }
}

the query is:
<update id="updateSingleEntry" parameterType="org.sample.myObj">
        UPDATE
        TEST_TABLE
        SET
        VALUE=#{value}
        WHERE
        KEY=#{key}
</update>

Original comment by giat...@hotmail.com on 21 Sep 2010 at 4:06

GoogleCodeExporter commented 9 years ago
I am afraid you can't. 

When you use a batch SqlSession, statements are not executed until you call 
.commit() so there is no way to return results. You will just get exceptions if 
something goes wrong. 

Original comment by eduardo.macarron on 16 Feb 2011 at 3:24