Re: 'insert/update/delete' return values

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: 'insert/update/delete' return values

Andrés Salcedo
The default value to be returned with BATCH is the number reported, as seen here.
Also, the default mode is not BATCH afaik.

The real failure is in docs. They should state it.

On Friday, June 18, 2010 9:52:05 AM UTC-5, Clinton Begin wrote:
Not your fault.  We'll have to consider 3 possible improvements.

* If BATCH is the default, perhaps it shouldn't be.
* We should be able to return the rows affected if there's only one result.
* The documentation should be more clear about this.

Clinton

On Fri, Jun 18, 2010 at 6:24 AM, q111111 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="frViLECIz7oJ">q2112...@...> wrote:
Mystery solved!
You are correct ... I did was using BATCH.
Switching to SIMPLE returned the correct number of effected rows.

Thank you!

On Jun 17, 3:15 pm, Clinton Begin <[hidden email]> wrote:
> Oh... you know what.... try this:
>
> SqlSession session = sqlMapper.openSession(*ExecutorType.SIMPLE*);
>
> If that works, you can configure it to be the default.  If the BATCH
> executor is in use, the update counts are being lost.  I think there's an
> issue already created for this, although not described this way.
>
> Clinton
>
>
>
>
>
> On Thu, Jun 17, 2010 at 12:17 PM, q111111 <[hidden email]> wrote:
> > Odd indeed!
>
> > PreparedStatement preparedStatement = con.prepareStatement("delete
> > from test");
> > int iRows = preparedStatement.executeUpdate();
> > System.out.println("iRows is " + iRows);
>
> > Output: iRows is 21
> > That is the correct answer ... 21 rows were in the table.
>
> > On Jun 17, 1:22 pm, Clinton Begin <[hidden email]> wrote:
> >> Wow, this sounds odd.  Have you tried just writing a quick JDBC test
> >> without ibatis to see if statement.executeUpdate() returns a valid
> >> value?
>
> >> On Thu, Jun 17, 2010 at 11:15 AM, Guy Rouillier <[hidden email]>
> wrote:
> >> > Very odd, I'm running out of ideas.  I went back to your original
> message.
> >> >  You said you are always seeing this same return value -2147482646 for
> >> > insert, update and delete?  And for delete you get the same value
> regardless
> >> > of how many rows are deleted?
>
> >> > Are you using ojdbc6.jar from 11g?  Make sure no other Oracle JARs
> exist on
> >> > your classpath.
>
> >> > On 6/17/2010 10:16 AM, q111111 wrote:
>
> >> >> I am using Eclipse, Oracle 11g, JDK 1.6.0 and  Windows.
>
> >> >> XML:
> >> >>     <delete id="delete">
> >> >>        delete from test
> >> >>     </delete>
>
> >> >> Mapper:
> >> >> public int delete() throws SQLException;
>
> >> >> Main.java:
> >> >>      int iRows = mapper.delete();
> >> >>      System.out/println("Number of rows deleted: " + iRows);
> >> >>      session.commit();
>
> >> >> Console message:
> >> >>    Number of rows deleted: -2147482646
>
> >> >> On Jun 17, 1:57 am, Guy Rouillier<[hidden email]>  wrote:
>
> >> >>> On 6/16/2010 3:26 PM, q111111 wrote:
>
> >> >>>> I did the switch over to using Java mappers and I am still getting
> the
> >> >>>> incorrect counts.
>
> >> >>>>             MyMapper mapper = session.getMapper(MyMapper.class);
> >> >>>>             return mapper.delete(domainObj);
>
> >> >>>> The underlying query is correctly deleting from the database.
> >> >>>> It is just the returning count that is incorrect.
> >> >>>> This is still returning number of rows deleted as -2147482646.
>
> >> >>>> Any other suggestions?
>
> >> >>>> If nothing else, I can count the number of rows pre and post delete
> >> >>>> and get the difference.
>
> >> >>> That shouldn't be necessary.  I just did a quick test, also using
> Oracle
> >> >>> 10g, starting with your code:
>
> >> >>> XML:
>
> >> >>>     <delete id="delete">
> >> >>>        delete from test
> >> >>>     </delete>
>
> >> >>> BTW, the code you posted was missing the closing angle bracket on the
> >> >>> first line.  I assume that was just a copy and paste error on your
> part;
> >> >>> iBATIS threw a read error exception without it.
>
> >> >>> mapper.java:
>
> >> >>>     int delete();
>
> >> >>> main.java:
>
> >> >>>     int iRows = mapper.delete();
> >> >>>     log.info("Number of rows deleted: " + iRows);
> >> >>>     session.commit();
>
> >> >>> Prints "Number of rows deleted: 30", which is the number of rows in
> my
> >> >>> test table.
>
> >> >>> I'm using JDK 1.6.0_16 on Windows.  The only other thing I see is
> that
> >> >>> you are not printing out the rows deleted immediately after
> invocation,
> >> >>> but are instead returning the value.  Print out the value immediately
> >> >>> after invocation, as I've done.  Maybe the issue is in the calling
> >> >>> routine and not in the iBATIS invocation.
>
> >> >>> --
> >> >>> Guy Rouillier
>
> >> > --
> >> > Guy Rouillier- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: 'insert/update/delete' return values

Andrés Salcedo
Just to add info about the default. It is SIMPLE. Taken from here.

public Executor newExecutor(Transaction transactionExecutorType executorType) {
    executorType = executorType == null ?  : executorType;
  executorType = executorType == null ? . : executorType;
    Executor executor;
    if (. == executorType) {
      executor = new BatchExecutor(this,transaction);
    } else if (. == executorType) {
      executor = new ReuseExecutor(this,transaction);
   else {
      executor = new SimpleExecutor(this,transaction);
    }

On Friday, February 1, 2013 12:35:22 PM UTC-5, Andrés Salcedo wrote:
The default value to be returned with BATCH is the number reported, as seen here.
Also, the default mode is not BATCH afaik.

The real failure is in docs. They should state it.

On Friday, June 18, 2010 9:52:05 AM UTC-5, Clinton Begin wrote:
Not your fault.  We'll have to consider 3 possible improvements.

* If BATCH is the default, perhaps it shouldn't be.
* We should be able to return the rows affected if there's only one result.
* The documentation should be more clear about this.

Clinton

On Fri, Jun 18, 2010 at 6:24 AM, q111111 <[hidden email]> wrote:
Mystery solved!
You are correct ... I did was using BATCH.
Switching to SIMPLE returned the correct number of effected rows.

Thank you!

On Jun 17, 3:15 pm, Clinton Begin <[hidden email]> wrote:
> Oh... you know what.... try this:
>
> SqlSession session = sqlMapper.openSession(*ExecutorType.SIMPLE*);
>
> If that works, you can configure it to be the default.  If the BATCH
> executor is in use, the update counts are being lost.  I think there's an
> issue already created for this, although not described this way.
>
> Clinton
>
>
>
>
>
> On Thu, Jun 17, 2010 at 12:17 PM, q111111 <[hidden email]> wrote:
> > Odd indeed!
>
> > PreparedStatement preparedStatement = con.prepareStatement("delete
> > from test");
> > int iRows = preparedStatement.executeUpdate();
> > System.out.println("iRows is " + iRows);
>
> > Output: iRows is 21
> > That is the correct answer ... 21 rows were in the table.
>
> > On Jun 17, 1:22 pm, Clinton Begin <[hidden email]> wrote:
> >> Wow, this sounds odd.  Have you tried just writing a quick JDBC test
> >> without ibatis to see if statement.executeUpdate() returns a valid
> >> value?
>
> >> On Thu, Jun 17, 2010 at 11:15 AM, Guy Rouillier <[hidden email]>
> wrote:
> >> > Very odd, I'm running out of ideas.  I went back to your original
> message.
> >> >  You said you are always seeing this same return value -2147482646 for
> >> > insert, update and delete?  And for delete you get the same value
> regardless
> >> > of how many rows are deleted?
>
> >> > Are you using ojdbc6.jar from 11g?  Make sure no other Oracle JARs
> exist on
> >> > your classpath.
>
> >> > On 6/17/2010 10:16 AM, q111111 wrote:
>
> >> >> I am using Eclipse, Oracle 11g, JDK 1.6.0 and  Windows.
>
> >> >> XML:
> >> >>     <delete id="delete">
> >> >>        delete from test
> >> >>     </delete>
>
> >> >> Mapper:
> >> >> public int delete() throws SQLException;
>
> >> >> Main.java:
> >> >>      int iRows = mapper.delete();
> >> >>      System.out/println("Number of rows deleted: " + iRows);
> >> >>      session.commit();
>
> >> >> Console message:
> >> >>    Number of rows deleted: -2147482646
>
> >> >> On Jun 17, 1:57 am, Guy Rouillier<[hidden email]>  wrote:
>
> >> >>> On 6/16/2010 3:26 PM, q111111 wrote:
>
> >> >>>> I did the switch over to using Java mappers and I am still getting
> the
> >> >>>> incorrect counts.
>
> >> >>>>             MyMapper mapper = session.getMapper(MyMapper.class);
> >> >>>>             return mapper.delete(domainObj);
>
> >> >>>> The underlying query is correctly deleting from the database.
> >> >>>> It is just the returning count that is incorrect.
> >> >>>> This is still returning number of rows deleted as -2147482646.
>
> >> >>>> Any other suggestions?
>
> >> >>>> If nothing else, I can count the number of rows pre and post delete
> >> >>>> and get the difference.
>
> >> >>> That shouldn't be necessary.  I just did a quick test, also using
> Oracle
> >> >>> 10g, starting with your code:
>
> >> >>> XML:
>
> >> >>>     <delete id="delete">
> >> >>>        delete from test
> >> >>>     </delete>
>
> >> >>> BTW, the code you posted was missing the closing angle bracket on the
> >> >>> first line.  I assume that was just a copy and paste error on your
> part;
> >> >>> iBATIS threw a read error exception without it.
>
> >> >>> mapper.java:
>
> >> >>>     int delete();
>
> >> >>> main.java:
>
> >> >>>     int iRows = mapper.delete();
> >> >>>     log.info("Number of rows deleted: " + iRows);
> >> >>>     session.commit();
>
> >> >>> Prints "Number of rows deleted: 30", which is the number of rows in
> my
> >> >>> test table.
>
> >> >>> I'm using JDK 1.6.0_16 on Windows.  The only other thing I see is
> that
> >> >>> you are not printing out the rows deleted immediately after
> invocation,
> >> >>> but are instead returning the value.  Print out the value immediately
> >> >>> after invocation, as I've done.  Maybe the issue is in the calling
> >> >>> routine and not in the iBATIS invocation.
>
> >> >>> --
> >> >>> Guy Rouillier
>
> >> > --
> >> > Guy Rouillier- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: 'insert/update/delete' return values

Andrii Rubtsov
Hi, I just wanted to confirm that the odd problem with magical number -2147482646 was observed and fixed by switching from BATCH to SIMPLE on the following env:

java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Personal Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

JDBC: ojdbc6 11.2.0.1.0

On Tuesday, February 5, 2013 6:17:31 PM UTC+2, Andrés Salcedo wrote:
Just to add info about the default. It is SIMPLE. Taken from here.

public Executor newExecutor(Transaction transactionExecutorType executorType) {
    executorType = executorType == null ? defaultExecutorType executorType;
  executorType = executorType == null ? ExecutorType.SIMPLE executorType;
    Executor executor;
    if (ExecutorType.BATCH == executorType) {
      executor = new BatchExecutor(this,transaction);
    } else if (ExecutorType.REUSE == executorType) {
      executor = new ReuseExecutor(this,transaction);
   else {
      executor = new SimpleExecutor(this,transaction);
    }

On Friday, February 1, 2013 12:35:22 PM UTC-5, Andrés Salcedo wrote:
The default value to be returned with BATCH is the number reported, as seen here.
Also, the default mode is not BATCH afaik.

The real failure is in docs. They should state it.

On Friday, June 18, 2010 9:52:05 AM UTC-5, Clinton Begin wrote:
Not your fault.  We'll have to consider 3 possible improvements.

* If BATCH is the default, perhaps it shouldn't be.
* We should be able to return the rows affected if there's only one result.
* The documentation should be more clear about this.

Clinton

On Fri, Jun 18, 2010 at 6:24 AM, q111111 <[hidden email]> wrote:
Mystery solved!
You are correct ... I did was using BATCH.
Switching to SIMPLE returned the correct number of effected rows.

Thank you!

On Jun 17, 3:15 pm, Clinton Begin <[hidden email]> wrote:
> Oh... you know what.... try this:
>
> SqlSession session = sqlMapper.openSession(*ExecutorType.SIMPLE*);
>
> If that works, you can configure it to be the default.  If the BATCH
> executor is in use, the update counts are being lost.  I think there's an
> issue already created for this, although not described this way.
>
> Clinton
>
>
>
>
>
> On Thu, Jun 17, 2010 at 12:17 PM, q111111 <[hidden email]> wrote:
> > Odd indeed!
>
> > PreparedStatement preparedStatement = con.prepareStatement("delete
> > from test");
> > int iRows = preparedStatement.executeUpdate();
> > System.out.println("iRows is " + iRows);
>
> > Output: iRows is 21
> > That is the correct answer ... 21 rows were in the table.
>
> > On Jun 17, 1:22 pm, Clinton Begin <[hidden email]> wrote:
> >> Wow, this sounds odd.  Have you tried just writing a quick JDBC test
> >> without ibatis to see if statement.executeUpdate() returns a valid
> >> value?
>
> >> On Thu, Jun 17, 2010 at 11:15 AM, Guy Rouillier <[hidden email]>
> wrote:
> >> > Very odd, I'm running out of ideas.  I went back to your original
> message.
> >> >  You said you are always seeing this same return value -2147482646 for
> >> > insert, update and delete?  And for delete you get the same value
> regardless
> >> > of how many rows are deleted?
>
> >> > Are you using ojdbc6.jar from 11g?  Make sure no other Oracle JARs
> exist on
> >> > your classpath.
>
> >> > On 6/17/2010 10:16 AM, q111111 wrote:
>
> >> >> I am using Eclipse, Oracle 11g, JDK 1.6.0 and  Windows.
>
> >> >> XML:
> >> >>     <delete id="delete">
> >> >>        delete from test
> >> >>     </delete>
>
> >> >> Mapper:
> >> >> public int delete() throws SQLException;
>
> >> >> Main.java:
> >> >>      int iRows = mapper.delete();
> >> >>      System.out/println("Number of rows deleted: " + iRows);
> >> >>      session.commit();
>
> >> >> Console message:
> >> >>    Number of rows deleted: -2147482646
>
> >> >> On Jun 17, 1:57 am, Guy Rouillier<[hidden email]>  wrote:
>
> >> >>> On 6/16/2010 3:26 PM, q111111 wrote:
>
> >> >>>> I did the switch over to using Java mappers and I am still getting
> the
> >> >>>> incorrect counts.
>
> >> >>>>             MyMapper mapper = session.getMapper(MyMapper.class);
> >> >>>>             return mapper.delete(domainObj);
>
> >> >>>> The underlying query is correctly deleting from the database.
> >> >>>> It is just the returning count that is incorrect.
> >> >>>> This is still returning number of rows deleted as -2147482646.
>
> >> >>>> Any other suggestions?
>
> >> >>>> If nothing else, I can count the number of rows pre and post delete
> >> >>>> and get the difference.
>
> >> >>> That shouldn't be necessary.  I just did a quick test, also using
> Oracle
> >> >>> 10g, starting with your code:
>
> >> >>> XML:
>
> >> >>>     <delete id="delete">
> >> >>>        delete from test
> >> >>>     </delete>
>
> >> >>> BTW, the code you posted was missing the closing angle bracket on the
> >> >>> first line.  I assume that was just a copy and paste error on your
> part;
> >> >>> iBATIS threw a read error exception without it.
>
> >> >>> mapper.java:
>
> >> >>>     int delete();
>
> >> >>> main.java:
>
> >> >>>     int iRows = mapper.delete();
> >> >>>     log.info("Number of rows deleted: " + iRows);
> >> >>>     session.commit();
>
> >> >>> Prints "Number of rows deleted: 30", which is the number of rows in
> my
> >> >>> test table.
>
> >> >>> I'm using JDK 1.6.0_16 on Windows.  The only other thing I see is
> that
> >> >>> you are not printing out the rows deleted immediately after
> invocation,
> >> >>> but are instead returning the value.  Print out the value immediately
> >> >>> after invocation, as I've done.  Maybe the issue is in the calling
> >> >>> routine and not in the iBATIS invocation.
>
> >> >>> --
> >> >>> Guy Rouillier
>
> >> > --
> >> > Guy Rouillier- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: 'insert/update/delete' return values

Eduardo Macarron
There is a reason for that extrange number.

Whe you use the batch executor all updates are cached and they are not sent to the DB untill the session ends, a flushStatements() is called, a select is executed or a commit / rollback is called.

The update method does not know how many records have been changed so it returns a negative number in a non-valid range. Exactly this:

public static final int BATCH_UPDATE_RETURN_VALUE = Integer.MIN_VALUE + 1002;

So, the rule is: any insert/update/delete over a batch session will return -<a href="tel:2147482646" value="+12147482646" target="_blank" style="font-size:12.727272033691406px;font-family:arial,sans-serif">2147482646 instead of the affected rows. It is not a bug or something that has to be fixed but a consecuence of using a batch session.


2013/4/12 Andrii Rubtsov <[hidden email]>
Hi, I just wanted to confirm that the odd problem with magical number -<a href="tel:2147482646" value="+12147482646" target="_blank">2147482646 was observed and fixed by switching from BATCH to SIMPLE on the following env:

java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Personal Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

JDBC: ojdbc6 11.2.0.1.0

On Tuesday, February 5, 2013 6:17:31 PM UTC+2, Andrés Salcedo wrote:
Just to add info about the default. It is SIMPLE. Taken from here.

public Executor newExecutor(Transaction transactionExecutorType executorType) {
    executorType = executorType == null ? defaultExecutorType executorType;
  executorType = executorType == null ? ExecutorType.SIMPLE executorType;
    Executor executor;
    if (ExecutorType.BATCH == executorType) {
      executor = new BatchExecutor(this,transaction);
    } else if (ExecutorType.REUSE == executorType) {
      executor = new ReuseExecutor(this,transaction);
   else {
      executor = new SimpleExecutor(this,transaction);
    }

On Friday, February 1, 2013 12:35:22 PM UTC-5, Andrés Salcedo wrote:
The default value to be returned with BATCH is the number reported, as seen here.
Also, the default mode is not BATCH afaik.

The real failure is in docs. They should state it.

On Friday, June 18, 2010 9:52:05 AM UTC-5, Clinton Begin wrote:
Not your fault.  We'll have to consider 3 possible improvements.

* If BATCH is the default, perhaps it shouldn't be.
* We should be able to return the rows affected if there's only one result.
* The documentation should be more clear about this.

Clinton

On Fri, Jun 18, 2010 at 6:24 AM, q111111 <[hidden email]> wrote:
Mystery solved!
You are correct ... I did was using BATCH.
Switching to SIMPLE returned the correct number of effected rows.

Thank you!

On Jun 17, 3:15 pm, Clinton Begin <[hidden email]> wrote:
> Oh... you know what.... try this:
>
> SqlSession session = sqlMapper.openSession(*ExecutorType.SIMPLE*);
>
> If that works, you can configure it to be the default.  If the BATCH
> executor is in use, the update counts are being lost.  I think there's an
> issue already created for this, although not described this way.
>
> Clinton
>
>
>
>
>
> On Thu, Jun 17, 2010 at 12:17 PM, q111111 <[hidden email]> wrote:
> > Odd indeed!
>
> > PreparedStatement preparedStatement = con.prepareStatement("delete
> > from test");
> > int iRows = preparedStatement.executeUpdate();
> > System.out.println("iRows is " + iRows);
>
> > Output: iRows is 21
> > That is the correct answer ... 21 rows were in the table.
>
> > On Jun 17, 1:22 pm, Clinton Begin <[hidden email]> wrote:
> >> Wow, this sounds odd.  Have you tried just writing a quick JDBC test
> >> without ibatis to see if statement.executeUpdate() returns a valid
> >> value?
>
> >> On Thu, Jun 17, 2010 at 11:15 AM, Guy Rouillier <[hidden email]>
> wrote:
> >> > Very odd, I'm running out of ideas.  I went back to your original
> message.
> >> >  You said you are always seeing this same return value -<a href="tel:2147482646" value="+12147482646" target="_blank">2147482646 for
> >> > insert, update and delete?  And for delete you get the same value
> regardless
> >> > of how many rows are deleted?
>
> >> > Are you using ojdbc6.jar from 11g?  Make sure no other Oracle JARs
> exist on
> >> > your classpath.
>
> >> > On 6/17/2010 10:16 AM, q111111 wrote:
>
> >> >> I am using Eclipse, Oracle 11g, JDK 1.6.0 and  Windows.
>
> >> >> XML:
> >> >>     <delete id="delete">
> >> >>        delete from test
> >> >>     </delete>
>
> >> >> Mapper:
> >> >> public int delete() throws SQLException;
>
> >> >> Main.java:
> >> >>      int iRows = mapper.delete();
> >> >>      System.out/println("Number of rows deleted: " + iRows);
> >> >>      session.commit();
>
> >> >> Console message:
> >> >>    Number of rows deleted: -<a href="tel:2147482646" value="+12147482646" target="_blank">2147482646
>
> >> >> On Jun 17, 1:57 am, Guy Rouillier<[hidden email]>  wrote:
>
> >> >>> On 6/16/2010 3:26 PM, q111111 wrote:
>
> >> >>>> I did the switch over to using Java mappers and I am still getting
> the
> >> >>>> incorrect counts.
>
> >> >>>>             MyMapper mapper = session.getMapper(MyMapper.class);
> >> >>>>             return mapper.delete(domainObj);
>
> >> >>>> The underlying query is correctly deleting from the database.
> >> >>>> It is just the returning count that is incorrect.
> >> >>>> This is still returning number of rows deleted as -<a href="tel:2147482646" value="+12147482646" target="_blank">2147482646.
>
> >> >>>> Any other suggestions?
>
> >> >>>> If nothing else, I can count the number of rows pre and post delete
> >> >>>> and get the difference.
>
> >> >>> That shouldn't be necessary.  I just did a quick test, also using
> Oracle
> >> >>> 10g, starting with your code:
>
> >> >>> XML:
>
> >> >>>     <delete id="delete">
> >> >>>        delete from test
> >> >>>     </delete>
>
> >> >>> BTW, the code you posted was missing the closing angle bracket on the
> >> >>> first line.  I assume that was just a copy and paste error on your
> part;
> >> >>> iBATIS threw a read error exception without it.
>
> >> >>> mapper.java:
>
> >> >>>     int delete();
>
> >> >>> main.java:
>
> >> >>>     int iRows = mapper.delete();
> >> >>>     log.info("Number of rows deleted: " + iRows);
> >> >>>     session.commit();
>
> >> >>> Prints "Number of rows deleted: 30", which is the number of rows in
> my
> >> >>> test table.
>
> >> >>> I'm using JDK 1.6.0_16 on Windows.  The only other thing I see is
> that
> >> >>> you are not printing out the rows deleted immediately after
> invocation,
> >> >>> but are instead returning the value.  Print out the value immediately
> >> >>> after invocation, as I've done.  Maybe the issue is in the calling
> >> >>> routine and not in the iBATIS invocation.
>
> >> >>> --
> >> >>> Guy Rouillier
>
> >> > --
> >> > Guy Rouillier- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: 'insert/update/delete' return values

Michael Plavnik
Eduardo,
One can regard having return value on the mapper method  as a clear indication for the flush, the same as query in the middle of updates.

Best regards,
Michael


On Friday, April 12, 2013 3:57:12 PM UTC-4, Eduardo wrote:
There is a reason for that extrange number.

Whe you use the batch executor all updates are cached and they are not sent to the DB untill the session ends, a flushStatements() is called, a select is executed or a commit / rollback is called.

The update method does not know how many records have been changed so it returns a negative number in a non-valid range. Exactly this:

public static final int BATCH_UPDATE_RETURN_VALUE = Integer.MIN_VALUE + 1002;

So, the rule is: any insert/update/delete over a batch session will return -2147482646 instead of the affected rows. It is not a bug or something that has to be fixed but a consecuence of using a batch session.


2013/4/12 Andrii Rubtsov <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="l0Kg59srT6UJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">andrii....@...>
Hi, I just wanted to confirm that the odd problem with magical number -2147482646 was observed and fixed by switching from BATCH to SIMPLE on the following env:

java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Personal Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

JDBC: ojdbc6 11.2.0.1.0

On Tuesday, February 5, 2013 6:17:31 PM UTC+2, Andrés Salcedo wrote:
Just to add info about the default. It is SIMPLE. Taken from <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/Configuration.java#Configuration.newExecutor%28org.apache.ibatis.transaction.Transaction%2Corg.apache.ibatis.session.ExecutorType%29" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23Configuration.newExecutor%2528org.apache.ibatis.transaction.Transaction%252Corg.apache.ibatis.session.ExecutorType%2529\46sa\75D\46sntz\0751\46usg\75AFQjCNF1CpK0Rk5JdzNvxCCB2Uk1K6aNYg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23Configuration.newExecutor%2528org.apache.ibatis.transaction.Transaction%252Corg.apache.ibatis.session.ExecutorType%2529\46sa\75D\46sntz\0751\46usg\75AFQjCNF1CpK0Rk5JdzNvxCCB2Uk1K6aNYg';return true;">here.

public <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/executor/Executor.java#Executor" title="org.apache.ibatis.executor.Executor" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FExecutor.java%23Executor\46sa\75D\46sntz\0751\46usg\75AFQjCNF-pco9pmtvYzhBI1ysvTYerSP4mg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FExecutor.java%23Executor\46sa\75D\46sntz\0751\46usg\75AFQjCNF-pco9pmtvYzhBI1ysvTYerSP4mg';return true;">Executor <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/Configuration.java#" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23\46sa\75D\46sntz\0751\46usg\75AFQjCNHdXkrM0POEDwcVBSH5P402zZMxAA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23\46sa\75D\46sntz\0751\46usg\75AFQjCNHdXkrM0POEDwcVBSH5P402zZMxAA';return true;">newExecutor(<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/transaction/Transaction.java#Transaction" title="org.apache.ibatis.transaction.Transaction" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Ftransaction%2FTransaction.java%23Transaction\46sa\75D\46sntz\0751\46usg\75AFQjCNFf9_LvRx_NDEMbi-TnPEExCpqldA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Ftransaction%2FTransaction.java%23Transaction\46sa\75D\46sntz\0751\46usg\75AFQjCNFf9_LvRx_NDEMbi-TnPEExCpqldA';return true;">Transaction transaction, <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType" title="org.apache.ibatis.session.ExecutorType" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType\46sa\75D\46sntz\0751\46usg\75AFQjCNFkOuQ7pPpJ8ntGcJntYAL_O7FUww';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType\46sa\75D\46sntz\0751\46usg\75AFQjCNFkOuQ7pPpJ8ntGcJntYAL_O7FUww';return true;">ExecutorType executorType) {
    executorType = executorType == null ? <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/Configuration.java#Configuration.0defaultExecutorType" title="ExecutorType defaultExecutorType" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23Configuration.0defaultExecutorType\46sa\75D\46sntz\0751\46usg\75AFQjCNGJV_fx6LecattJRM7DUsKbU1ostA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23Configuration.0defaultExecutorType\46sa\75D\46sntz\0751\46usg\75AFQjCNGJV_fx6LecattJRM7DUsKbU1ostA';return true;">defaultExecutorType executorType;
  executorType = executorType == null ? <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0SIMPLE" title="ExecutorType SIMPLE" style="font-size:x-small" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0SIMPLE\46sa\75D\46sntz\0751\46usg\75AFQjCNFb8KRR-xVE2PWx4f8FCVyskkCMPw';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0SIMPLE\46sa\75D\46sntz\0751\46usg\75AFQjCNFb8KRR-xVE2PWx4f8FCVyskkCMPw';return true;">ExecutorType.<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0SIMPLE" title="ExecutorType SIMPLE" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0SIMPLE\46sa\75D\46sntz\0751\46usg\75AFQjCNFb8KRR-xVE2PWx4f8FCVyskkCMPw';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0SIMPLE\46sa\75D\46sntz\0751\46usg\75AFQjCNFb8KRR-xVE2PWx4f8FCVyskkCMPw';return true;">SIMPLE executorType;
    <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/executor/Executor.java#Executor" title="org.apache.ibatis.executor.Executor" style="font-size:x-small" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FExecutor.java%23Executor\46sa\75D\46sntz\0751\46usg\75AFQjCNF-pco9pmtvYzhBI1ysvTYerSP4mg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FExecutor.java%23Executor\46sa\75D\46sntz\0751\46usg\75AFQjCNF-pco9pmtvYzhBI1ysvTYerSP4mg';return true;">Executor executor;
    if (<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0BATCH" title="ExecutorType BATCH" style="font-size:x-small" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0BATCH\46sa\75D\46sntz\0751\46usg\75AFQjCNHr-B7XYesVBCTbVrFPfiGMmAlDwg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0BATCH\46sa\75D\46sntz\0751\46usg\75AFQjCNHr-B7XYesVBCTbVrFPfiGMmAlDwg';return true;">ExecutorType.<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0BATCH" title="ExecutorType BATCH" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0BATCH\46sa\75D\46sntz\0751\46usg\75AFQjCNHr-B7XYesVBCTbVrFPfiGMmAlDwg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0BATCH\46sa\75D\46sntz\0751\46usg\75AFQjCNHr-B7XYesVBCTbVrFPfiGMmAlDwg';return true;">BATCH == executorType) {
      executor = new <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/executor/BatchExecutor.java#BatchExecutor" title="org.apache.ibatis.executor.BatchExecutor" style="font-size:x-small" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FBatchExecutor.java%23BatchExecutor\46sa\75D\46sntz\0751\46usg\75AFQjCNElRmwx6ME-b3qLH2jtndz6LjJlrA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FBatchExecutor.java%23BatchExecutor\46sa\75D\46sntz\0751\46usg\75AFQjCNElRmwx6ME-b3qLH2jtndz6LjJlrA';return true;">BatchExecutor(this,transaction);
    } else if (<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0REUSE" title="ExecutorType REUSE" style="font-size:x-small" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0REUSE\46sa\75D\46sntz\0751\46usg\75AFQjCNER1cnYtmwmopHUR39cEohj9T81-A';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0REUSE\46sa\75D\46sntz\0751\46usg\75AFQjCNER1cnYtmwmopHUR39cEohj9T81-A';return true;">ExecutorType.<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0REUSE" title="ExecutorType REUSE" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0REUSE\46sa\75D\46sntz\0751\46usg\75AFQjCNER1cnYtmwmopHUR39cEohj9T81-A';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0REUSE\46sa\75D\46sntz\0751\46usg\75AFQjCNER1cnYtmwmopHUR39cEohj9T81-A';return true;">REUSE == executorType) {
      executor = new <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/executor/ReuseExecutor.java#ReuseExecutor" title="org.apache.ibatis.executor.ReuseExecutor" style="font-size:x-small" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FReuseExecutor.java%23ReuseExecutor\46sa\75D\46sntz\0751\46usg\75AFQjCNEMXW4CCk97Ijg9DiFFtOUmCJDbcg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FReuseExecutor.java%23ReuseExecutor\46sa\75D\46sntz\0751\46usg\75AFQjCNEMXW4CCk97Ijg9DiFFtOUmCJDbcg';return true;">ReuseExecutor(this,transaction);
   else {
      executor = new <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/executor/SimpleExecutor.java#SimpleExecutor" title="org.apache.ibatis.executor.SimpleExecutor" style="font-size:x-small" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FSimpleExecutor.java%23SimpleExecutor\46sa\75D\46sntz\0751\46usg\75AFQjCNECauJdLJla74LzOc1Evcd2wDcCTg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FSimpleExecutor.java%23SimpleExecutor\46sa\75D\46sntz\0751\46usg\75AFQjCNECauJdLJla74LzOc1Evcd2wDcCTg';return true;">SimpleExecutor(this,transaction);
    }

On Friday, February 1, 2013 12:35:22 PM UTC-5, Andrés Salcedo wrote:
The default value to be returned with BATCH is the number reported, as seen <a href="http://www.jarvana.com/jarvana/view/org/mybatis/mybatis/3.0.1/mybatis-3.0.1-javadoc.jar!/org/apache/ibatis/executor/BatchExecutor.html#BATCH_UPDATE_RETURN_VALUE" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.jarvana.com%2Fjarvana%2Fview%2Forg%2Fmybatis%2Fmybatis%2F3.0.1%2Fmybatis-3.0.1-javadoc.jar!%2Forg%2Fapache%2Fibatis%2Fexecutor%2FBatchExecutor.html%23BATCH_UPDATE_RETURN_VALUE\46sa\75D\46sntz\0751\46usg\75AFQjCNGsH2gSGuJsUhJ2KDmrmltsVkeRsg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.jarvana.com%2Fjarvana%2Fview%2Forg%2Fmybatis%2Fmybatis%2F3.0.1%2Fmybatis-3.0.1-javadoc.jar!%2Forg%2Fapache%2Fibatis%2Fexecutor%2FBatchExecutor.html%23BATCH_UPDATE_RETURN_VALUE\46sa\75D\46sntz\0751\46usg\75AFQjCNGsH2gSGuJsUhJ2KDmrmltsVkeRsg';return true;">here.
Also, the default mode is not BATCH afaik.

The real failure is in docs. They should state it.

On Friday, June 18, 2010 9:52:05 AM UTC-5, Clinton Begin wrote:
Not your fault.  We'll have to consider 3 possible improvements.

* If BATCH is the default, perhaps it shouldn't be.
* We should be able to return the rows affected if there's only one result.
* The documentation should be more clear about this.

Clinton

On Fri, Jun 18, 2010 at 6:24 AM, q111111 <[hidden email]> wrote:
Mystery solved!
You are correct ... I did was using BATCH.
Switching to SIMPLE returned the correct number of effected rows.

Thank you!

On Jun 17, 3:15 pm, Clinton Begin <[hidden email]> wrote:
> Oh... you know what.... try this:
>
> SqlSession session = sqlMapper.openSession(*ExecutorType.SIMPLE*);
>
> If that works, you can configure it to be the default.  If the BATCH
> executor is in use, the update counts are being lost.  I think there's an
> issue already created for this, although not described this way.
>
> Clinton
>
>
>
>
>
> On Thu, Jun 17, 2010 at 12:17 PM, q111111 <[hidden email]> wrote:
> > Odd indeed!
>
> > PreparedStatement preparedStatement = con.prepareStatement("delete
> > from test");
> > int iRows = preparedStatement.executeUpdate();
> > System.out.println("iRows is " + iRows);
>
> > Output: iRows is 21
> > That is the correct answer ... 21 rows were in the table.
>
> > On Jun 17, 1:22 pm, Clinton Begin <[hidden email]> wrote:
> >> Wow, this sounds odd.  Have you tried just writing a quick JDBC test
> >> without ibatis to see if statement.executeUpdate() returns a valid
> >> value?
>
> >> On Thu, Jun 17, 2010 at 11:15 AM, Guy Rouillier <[hidden email]>
> wrote:
> >> > Very odd, I'm running out of ideas.  I went back to your original
> message.
> >> >  You said you are always seeing this same return value -2147482646 for
> >> > insert, update and delete?  And for delete you get the same value
> regardless
> >> > of how many rows are deleted?
>
> >> > Are you using ojdbc6.jar from 11g?  Make sure no other Oracle JARs
> exist on
> >> > your classpath.
>
> >> > On 6/17/2010 10:16 AM, q111111 wrote:
>
> >> >> I am using Eclipse, Oracle 11g, JDK 1.6.0 and  Windows.
>
> >> >> XML:
> >> >>     <delete id="delete">
> >> >>        delete from test
> >> >>     </delete>
>
> >> >> Mapper:
> >> >> public int delete() throws SQLException;
>
> >> >> Main.java:
> >> >>      int iRows = mapper.delete();
> >> >>      System.out/println("Number of rows deleted: " + iRows);
> >> >>      session.commit();
>
> >> >> Console message:
> >> >>    Number of rows deleted: -2147482646
>
> >> >> On Jun 17, 1:57 am, Guy Rouillier<[hidden email]>  wrote:
>
> >> >>> On 6/16/2010 3:26 PM, q111111 wrote:
>
> >> >>>> I did the switch over to using Java mappers and I am still getting
> the
> >> >>>> incorrect counts.
>
> >> >>>>             MyMapper mapper = session.getMapper(MyMapper.class);
> >> >>>>             return mapper.delete(domainObj);
>
> >> >>>> The underlying query is correctly deleting from the database.
> >> >>>> It is just the returning count that is incorrect.
> >> >>>> This is still returning number of rows deleted as -2147482646.
>
> >> >>>> Any other suggestions?
>
> >> >>>> If nothing else, I can count the number of rows pre and post delete
> >> >>>> and get the difference.
>
> >> >>> That shouldn't be necessary.  I just did a quick test, also using
> Oracle
> >> >>> 10g, starting with your code:
>
> >> >>> XML:
>
> >> >>>     <delete id="delete">
> >> >>>        delete from test
> >> >>>     </delete>
>
> >> >>> BTW, the code you posted was missing the closing angle bracket on the
> >> >>> first line.  I assume that was just a copy and paste error on your
> part;
> >> >>> iBATIS threw a read error exception without it.
>
> >> >>> mapper.java:
>
> >> >>>     int delete();
>
> >> >>> main.java:
>
> >> >>>     int iRows = mapper.delete();
> >> >>>     <a href="http://log.info" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flog.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGiFwT-1qFB2PcvymGq972yAwReIA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flog.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGiFwT-1qFB2PcvymGq972yAwReIA';return true;">log.info("Number of rows deleted: " + iRows);
> >> >>>     session.commit();
>
> >> >>> Prints "Number of rows deleted: 30", which is the number of rows in
> my
> >> >>> test table.
>
> >> >>> I'm using JDK 1.6.0_16 on Windows.  The only other thing I see is
> that
> >> >>> you are not printing out the rows deleted immediately after
> invocation,
> >> >>> but are instead returning the value.  Print out the value immediately
> >> >>> after invocation, as I've done.  Maybe the issue is in the calling
> >> >>> routine and not in the iBATIS invocation.
>
> >> >>> --
> >> >>> Guy Rouillier
>
> >> > --
> >> > Guy Rouillier- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="l0Kg59srT6UJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/groups/opt_out" target="_blank" onmousedown="this.href='https://groups.google.com/groups/opt_out';return true;" onclick="this.href='https://groups.google.com/groups/opt_out';return true;">https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: 'insert/update/delete' return values

아미
Eduardo,

The mybatis batch executor works like adding the query to the batch queue and doing the batch job after.
But i agree with Michael Plavnik, we can get how many row affected when the query was flushed or in some middle time.

And i think a lot of people using mybatis(Simple or Batch or with other Executors) want to know how many rows are inserted/updated to the table.


2014년 7월 16일 수요일 오전 2시 22분 13초 UTC+9, Michael Plavnik 님의 말:
Eduardo,
One can regard having return value on the mapper method  as a clear indication for the flush, the same as query in the middle of updates.

Best regards,
Michael


On Friday, April 12, 2013 3:57:12 PM UTC-4, Eduardo wrote:
There is a reason for that extrange number.

Whe you use the batch executor all updates are cached and they are not sent to the DB untill the session ends, a flushStatements() is called, a select is executed or a commit / rollback is called.

The update method does not know how many records have been changed so it returns a negative number in a non-valid range. Exactly this:

public static final int BATCH_UPDATE_RETURN_VALUE = Integer.MIN_VALUE + 1002;

So, the rule is: any insert/update/delete over a batch session will return -2147482646 instead of the affected rows. It is not a bug or something that has to be fixed but a consecuence of using a batch session.


2013/4/12 Andrii Rubtsov <[hidden email]>
Hi, I just wanted to confirm that the odd problem with magical number -2147482646 was observed and fixed by switching from BATCH to SIMPLE on the following env:

java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Personal Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

JDBC: ojdbc6 11.2.0.1.0

On Tuesday, February 5, 2013 6:17:31 PM UTC+2, Andrés Salcedo wrote:
Just to add info about the default. It is SIMPLE. Taken from <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/Configuration.java#Configuration.newExecutor%28org.apache.ibatis.transaction.Transaction%2Corg.apache.ibatis.session.ExecutorType%29" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23Configuration.newExecutor%2528org.apache.ibatis.transaction.Transaction%252Corg.apache.ibatis.session.ExecutorType%2529\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF1CpK0Rk5JdzNvxCCB2Uk1K6aNYg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23Configuration.newExecutor%2528org.apache.ibatis.transaction.Transaction%252Corg.apache.ibatis.session.ExecutorType%2529\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF1CpK0Rk5JdzNvxCCB2Uk1K6aNYg&#39;;return true;">here.

public <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/executor/Executor.java#Executor" title="org.apache.ibatis.executor.Executor" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FExecutor.java%23Executor\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF-pco9pmtvYzhBI1ysvTYerSP4mg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FExecutor.java%23Executor\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF-pco9pmtvYzhBI1ysvTYerSP4mg&#39;;return true;">Executor <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/Configuration.java#" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHdXkrM0POEDwcVBSH5P402zZMxAA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHdXkrM0POEDwcVBSH5P402zZMxAA&#39;;return true;">newExecutor(<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/transaction/Transaction.java#Transaction" title="org.apache.ibatis.transaction.Transaction" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Ftransaction%2FTransaction.java%23Transaction\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFf9_LvRx_NDEMbi-TnPEExCpqldA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Ftransaction%2FTransaction.java%23Transaction\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFf9_LvRx_NDEMbi-TnPEExCpqldA&#39;;return true;">Transaction transaction, <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType" title="org.apache.ibatis.session.ExecutorType" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFkOuQ7pPpJ8ntGcJntYAL_O7FUww&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFkOuQ7pPpJ8ntGcJntYAL_O7FUww&#39;;return true;">ExecutorType executorType) {
    executorType = executorType == null ? <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/Configuration.java#Configuration.0defaultExecutorType" title="ExecutorType defaultExecutorType" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23Configuration.0defaultExecutorType\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGJV_fx6LecattJRM7DUsKbU1ostA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FConfiguration.java%23Configuration.0defaultExecutorType\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGJV_fx6LecattJRM7DUsKbU1ostA&#39;;return true;">defaultExecutorType executorType;
  executorType = executorType == null ? <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0SIMPLE" title="ExecutorType SIMPLE" style="font-size:x-small" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0SIMPLE\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFb8KRR-xVE2PWx4f8FCVyskkCMPw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0SIMPLE\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFb8KRR-xVE2PWx4f8FCVyskkCMPw&#39;;return true;">ExecutorType.<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0SIMPLE" title="ExecutorType SIMPLE" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0SIMPLE\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFb8KRR-xVE2PWx4f8FCVyskkCMPw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0SIMPLE\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFb8KRR-xVE2PWx4f8FCVyskkCMPw&#39;;return true;">SIMPLE executorType;
    <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/executor/Executor.java#Executor" title="org.apache.ibatis.executor.Executor" style="font-size:x-small" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FExecutor.java%23Executor\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF-pco9pmtvYzhBI1ysvTYerSP4mg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FExecutor.java%23Executor\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF-pco9pmtvYzhBI1ysvTYerSP4mg&#39;;return true;">Executor executor;
    if (<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0BATCH" title="ExecutorType BATCH" style="font-size:x-small" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0BATCH\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHr-B7XYesVBCTbVrFPfiGMmAlDwg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0BATCH\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHr-B7XYesVBCTbVrFPfiGMmAlDwg&#39;;return true;">ExecutorType.<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0BATCH" title="ExecutorType BATCH" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0BATCH\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHr-B7XYesVBCTbVrFPfiGMmAlDwg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0BATCH\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHr-B7XYesVBCTbVrFPfiGMmAlDwg&#39;;return true;">BATCH == executorType) {
      executor = new <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/executor/BatchExecutor.java#BatchExecutor" title="org.apache.ibatis.executor.BatchExecutor" style="font-size:x-small" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FBatchExecutor.java%23BatchExecutor\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNElRmwx6ME-b3qLH2jtndz6LjJlrA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FBatchExecutor.java%23BatchExecutor\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNElRmwx6ME-b3qLH2jtndz6LjJlrA&#39;;return true;">BatchExecutor(this,transaction);
    } else if (<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0REUSE" title="ExecutorType REUSE" style="font-size:x-small" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0REUSE\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNER1cnYtmwmopHUR39cEohj9T81-A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0REUSE\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNER1cnYtmwmopHUR39cEohj9T81-A&#39;;return true;">ExecutorType.<a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/session/ExecutorType.java#ExecutorType.0REUSE" title="ExecutorType REUSE" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0REUSE\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNER1cnYtmwmopHUR39cEohj9T81-A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fsession%2FExecutorType.java%23ExecutorType.0REUSE\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNER1cnYtmwmopHUR39cEohj9T81-A&#39;;return true;">REUSE == executorType) {
      executor = new <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/executor/ReuseExecutor.java#ReuseExecutor" title="org.apache.ibatis.executor.ReuseExecutor" style="font-size:x-small" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FReuseExecutor.java%23ReuseExecutor\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEMXW4CCk97Ijg9DiFFtOUmCJDbcg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FReuseExecutor.java%23ReuseExecutor\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEMXW4CCk97Ijg9DiFFtOUmCJDbcg&#39;;return true;">ReuseExecutor(this,transaction);
   else {
      executor = new <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.mybatis/mybatis/3.0.1/org/apache/ibatis/executor/SimpleExecutor.java#SimpleExecutor" title="org.apache.ibatis.executor.SimpleExecutor" style="font-size:x-small" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FSimpleExecutor.java%23SimpleExecutor\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNECauJdLJla74LzOc1Evcd2wDcCTg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrepcode.com%2Ffile%2Frepo1.maven.org%2Fmaven2%2Forg.mybatis%2Fmybatis%2F3.0.1%2Forg%2Fapache%2Fibatis%2Fexecutor%2FSimpleExecutor.java%23SimpleExecutor\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNECauJdLJla74LzOc1Evcd2wDcCTg&#39;;return true;">SimpleExecutor(this,transaction);
    }

On Friday, February 1, 2013 12:35:22 PM UTC-5, Andrés Salcedo wrote:
The default value to be returned with BATCH is the number reported, as seen <a href="http://www.jarvana.com/jarvana/view/org/mybatis/mybatis/3.0.1/mybatis-3.0.1-javadoc.jar!/org/apache/ibatis/executor/BatchExecutor.html#BATCH_UPDATE_RETURN_VALUE" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.jarvana.com%2Fjarvana%2Fview%2Forg%2Fmybatis%2Fmybatis%2F3.0.1%2Fmybatis-3.0.1-javadoc.jar!%2Forg%2Fapache%2Fibatis%2Fexecutor%2FBatchExecutor.html%23BATCH_UPDATE_RETURN_VALUE\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGsH2gSGuJsUhJ2KDmrmltsVkeRsg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.jarvana.com%2Fjarvana%2Fview%2Forg%2Fmybatis%2Fmybatis%2F3.0.1%2Fmybatis-3.0.1-javadoc.jar!%2Forg%2Fapache%2Fibatis%2Fexecutor%2FBatchExecutor.html%23BATCH_UPDATE_RETURN_VALUE\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGsH2gSGuJsUhJ2KDmrmltsVkeRsg&#39;;return true;">here.
Also, the default mode is not BATCH afaik.

The real failure is in docs. They should state it.

On Friday, June 18, 2010 9:52:05 AM UTC-5, Clinton Begin wrote:
Not your fault.  We'll have to consider 3 possible improvements.

* If BATCH is the default, perhaps it shouldn't be.
* We should be able to return the rows affected if there's only one result.
* The documentation should be more clear about this.

Clinton

On Fri, Jun 18, 2010 at 6:24 AM, q111111 <[hidden email]> wrote:
Mystery solved!
You are correct ... I did was using BATCH.
Switching to SIMPLE returned the correct number of effected rows.

Thank you!

On Jun 17, 3:15 pm, Clinton Begin <[hidden email]> wrote:
> Oh... you know what.... try this:
>
> SqlSession session = sqlMapper.openSession(*ExecutorType.SIMPLE*);
>
> If that works, you can configure it to be the default.  If the BATCH
> executor is in use, the update counts are being lost.  I think there's an
> issue already created for this, although not described this way.
>
> Clinton
>
>
>
>
>
> On Thu, Jun 17, 2010 at 12:17 PM, q111111 <[hidden email]> wrote:
> > Odd indeed!
>
> > PreparedStatement preparedStatement = con.prepareStatement("delete
> > from test");
> > int iRows = preparedStatement.executeUpdate();
> > System.out.println("iRows is " + iRows);
>
> > Output: iRows is 21
> > That is the correct answer ... 21 rows were in the table.
>
> > On Jun 17, 1:22 pm, Clinton Begin <[hidden email]> wrote:
> >> Wow, this sounds odd.  Have you tried just writing a quick JDBC test
> >> without ibatis to see if statement.executeUpdate() returns a valid
> >> value?
>
> >> On Thu, Jun 17, 2010 at 11:15 AM, Guy Rouillier <[hidden email]>
> wrote:
> >> > Very odd, I'm running out of ideas.  I went back to your original
> message.
> >> >  You said you are always seeing this same return value -2147482646 for
> >> > insert, update and delete?  And for delete you get the same value
> regardless
> >> > of how many rows are deleted?
>
> >> > Are you using ojdbc6.jar from 11g?  Make sure no other Oracle JARs
> exist on
> >> > your classpath.
>
> >> > On 6/17/2010 10:16 AM, q111111 wrote:
>
> >> >> I am using Eclipse, Oracle 11g, JDK 1.6.0 and  Windows.
>
> >> >> XML:
> >> >>     <delete id="delete">
> >> >>        delete from test
> >> >>     </delete>
>
> >> >> Mapper:
> >> >> public int delete() throws SQLException;
>
> >> >> Main.java:
> >> >>      int iRows = mapper.delete();
> >> >>      System.out/println("Number of rows deleted: " + iRows);
> >> >>      session.commit();
>
> >> >> Console message:
> >> >>    Number of rows deleted: -2147482646
>
> >> >> On Jun 17, 1:57 am, Guy Rouillier<[hidden email]>  wrote:
>
> >> >>> On 6/16/2010 3:26 PM, q111111 wrote:
>
> >> >>>> I did the switch over to using Java mappers and I am still getting
> the
> >> >>>> incorrect counts.
>
> >> >>>>             MyMapper mapper = session.getMapper(MyMapper.class);
> >> >>>>             return mapper.delete(domainObj);
>
> >> >>>> The underlying query is correctly deleting from the database.
> >> >>>> It is just the returning count that is incorrect.
> >> >>>> This is still returning number of rows deleted as -2147482646.
>
> >> >>>> Any other suggestions?
>
> >> >>>> If nothing else, I can count the number of rows pre and post delete
> >> >>>> and get the difference.
>
> >> >>> That shouldn't be necessary.  I just did a quick test, also using
> Oracle
> >> >>> 10g, starting with your code:
>
> >> >>> XML:
>
> >> >>>     <delete id="delete">
> >> >>>        delete from test
> >> >>>     </delete>
>
> >> >>> BTW, the code you posted was missing the closing angle bracket on the
> >> >>> first line.  I assume that was just a copy and paste error on your
> part;
> >> >>> iBATIS threw a read error exception without it.
>
> >> >>> mapper.java:
>
> >> >>>     int delete();
>
> >> >>> main.java:
>
> >> >>>     int iRows = mapper.delete();
> >> >>>     <a href="http://log.info" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Flog.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGiFwT-1qFB2PcvymGq972yAwReIA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Flog.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGiFwT-1qFB2PcvymGq972yAwReIA&#39;;return true;">log.info("Number of rows deleted: " + iRows);
> >> >>>     session.commit();
>
> >> >>> Prints "Number of rows deleted: 30", which is the number of rows in
> my
> >> >>> test table.
>
> >> >>> I'm using JDK 1.6.0_16 on Windows.  The only other thing I see is
> that
> >> >>> you are not printing out the rows deleted immediately after
> invocation,
> >> >>> but are instead returning the value.  Print out the value immediately
> >> >>> after invocation, as I've done.  Maybe the issue is in the calling
> >> >>> routine and not in the iBATIS invocation.
>
> >> >>> --
> >> >>> Guy Rouillier
>
> >> > --
> >> > Guy Rouillier- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/groups/opt_out" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/groups/opt_out&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/groups/opt_out&#39;;return true;">https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/5fc5c825-aa0f-4a74-aae3-6181957983a8%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: 'insert/update/delete' return values

Iwao AVE!
Hi,

SqlSession#flushStatement() returns a list of BatchResult.
And BatchResult#getUpdateCount() returns the result of Statement#executeBatch() which is...

> an array of update counts containing one element for each command in the batch.


Regards,
Iwao

On Thu, Jun 13, 2019 at 4:42 PM 아미 <[hidden email]> wrote:
Eduardo,

The mybatis batch executor works like adding the query to the batch queue and doing the batch job after.
But i agree with Michael Plavnik, we can get how many row affected when the query was flushed or in some middle time.

And i think a lot of people using mybatis(Simple or Batch or with other Executors) want to know how many rows are inserted/updated to the table.


2014년 7월 16일 수요일 오전 2시 22분 13초 UTC+9, Michael Plavnik 님의 말:
Eduardo,
One can regard having return value on the mapper method  as a clear indication for the flush, the same as query in the middle of updates.

Best regards,
Michael


On Friday, April 12, 2013 3:57:12 PM UTC-4, Eduardo wrote:
There is a reason for that extrange number.

Whe you use the batch executor all updates are cached and they are not sent to the DB untill the session ends, a flushStatements() is called, a select is executed or a commit / rollback is called.

The update method does not know how many records have been changed so it returns a negative number in a non-valid range. Exactly this:

public static final int BATCH_UPDATE_RETURN_VALUE = Integer.MIN_VALUE + 1002;

So, the rule is: any insert/update/delete over a batch session will return -2147482646 instead of the affected rows. It is not a bug or something that has to be fixed but a consecuence of using a batch session.


2013/4/12 Andrii Rubtsov <[hidden email]>
Hi, I just wanted to confirm that the odd problem with magical number -2147482646 was observed and fixed by switching from BATCH to SIMPLE on the following env:

java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Personal Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

JDBC: ojdbc6 11.2.0.1.0

On Tuesday, February 5, 2013 6:17:31 PM UTC+2, Andrés Salcedo wrote:
Just to add info about the default. It is SIMPLE. Taken from here.

public Executor newExecutor(Transaction transactionExecutorType executorType) {
    executorType = executorType == null ? defaultExecutorType executorType;
  executorType = executorType == null ? ExecutorType.SIMPLE executorType;
    Executor executor;
    if (ExecutorType.BATCH == executorType) {
      executor = new BatchExecutor(this,transaction);
    } else if (ExecutorType.REUSE == executorType) {
      executor = new ReuseExecutor(this,transaction);
   else {
      executor = new SimpleExecutor(this,transaction);
    }

On Friday, February 1, 2013 12:35:22 PM UTC-5, Andrés Salcedo wrote:
The default value to be returned with BATCH is the number reported, as seen here.
Also, the default mode is not BATCH afaik.

The real failure is in docs. They should state it.

On Friday, June 18, 2010 9:52:05 AM UTC-5, Clinton Begin wrote:
Not your fault.  We'll have to consider 3 possible improvements.

* If BATCH is the default, perhaps it shouldn't be.
* We should be able to return the rows affected if there's only one result.
* The documentation should be more clear about this.

Clinton

On Fri, Jun 18, 2010 at 6:24 AM, q111111 <[hidden email]> wrote:
Mystery solved!
You are correct ... I did was using BATCH.
Switching to SIMPLE returned the correct number of effected rows.

Thank you!

On Jun 17, 3:15 pm, Clinton Begin <[hidden email]> wrote:
> Oh... you know what.... try this:
>
> SqlSession session = sqlMapper.openSession(*ExecutorType.SIMPLE*);
>
> If that works, you can configure it to be the default.  If the BATCH
> executor is in use, the update counts are being lost.  I think there's an
> issue already created for this, although not described this way.
>
> Clinton
>
>
>
>
>
> On Thu, Jun 17, 2010 at 12:17 PM, q111111 <[hidden email]> wrote:
> > Odd indeed!
>
> > PreparedStatement preparedStatement = con.prepareStatement("delete
> > from test");
> > int iRows = preparedStatement.executeUpdate();
> > System.out.println("iRows is " + iRows);
>
> > Output: iRows is 21
> > That is the correct answer ... 21 rows were in the table.
>
> > On Jun 17, 1:22 pm, Clinton Begin <[hidden email]> wrote:
> >> Wow, this sounds odd.  Have you tried just writing a quick JDBC test
> >> without ibatis to see if statement.executeUpdate() returns a valid
> >> value?
>
> >> On Thu, Jun 17, 2010 at 11:15 AM, Guy Rouillier <[hidden email]>
> wrote:
> >> > Very odd, I'm running out of ideas.  I went back to your original
> message.
> >> >  You said you are always seeing this same return value -2147482646 for
> >> > insert, update and delete?  And for delete you get the same value
> regardless
> >> > of how many rows are deleted?
>
> >> > Are you using ojdbc6.jar from 11g?  Make sure no other Oracle JARs
> exist on
> >> > your classpath.
>
> >> > On 6/17/2010 10:16 AM, q111111 wrote:
>
> >> >> I am using Eclipse, Oracle 11g, JDK 1.6.0 and  Windows.
>
> >> >> XML:
> >> >>     <delete id="delete">
> >> >>        delete from test
> >> >>     </delete>
>
> >> >> Mapper:
> >> >> public int delete() throws SQLException;
>
> >> >> Main.java:
> >> >>      int iRows = mapper.delete();
> >> >>      System.out/println("Number of rows deleted: " + iRows);
> >> >>      session.commit();
>
> >> >> Console message:
> >> >>    Number of rows deleted: -2147482646
>
> >> >> On Jun 17, 1:57 am, Guy Rouillier<[hidden email]>  wrote:
>
> >> >>> On 6/16/2010 3:26 PM, q111111 wrote:
>
> >> >>>> I did the switch over to using Java mappers and I am still getting
> the
> >> >>>> incorrect counts.
>
> >> >>>>             MyMapper mapper = session.getMapper(MyMapper.class);
> >> >>>>             return mapper.delete(domainObj);
>
> >> >>>> The underlying query is correctly deleting from the database.
> >> >>>> It is just the returning count that is incorrect.
> >> >>>> This is still returning number of rows deleted as -2147482646.
>
> >> >>>> Any other suggestions?
>
> >> >>>> If nothing else, I can count the number of rows pre and post delete
> >> >>>> and get the difference.
>
> >> >>> That shouldn't be necessary.  I just did a quick test, also using
> Oracle
> >> >>> 10g, starting with your code:
>
> >> >>> XML:
>
> >> >>>     <delete id="delete">
> >> >>>        delete from test
> >> >>>     </delete>
>
> >> >>> BTW, the code you posted was missing the closing angle bracket on the
> >> >>> first line.  I assume that was just a copy and paste error on your
> part;
> >> >>> iBATIS threw a read error exception without it.
>
> >> >>> mapper.java:
>
> >> >>>     int delete();
>
> >> >>> main.java:
>
> >> >>>     int iRows = mapper.delete();
> >> >>>     log.info("Number of rows deleted: " + iRows);
> >> >>>     session.commit();
>
> >> >>> Prints "Number of rows deleted: 30", which is the number of rows in
> my
> >> >>> test table.
>
> >> >>> I'm using JDK 1.6.0_16 on Windows.  The only other thing I see is
> that
> >> >>> you are not printing out the rows deleted immediately after
> invocation,
> >> >>> but are instead returning the value.  Print out the value immediately
> >> >>> after invocation, as I've done.  Maybe the issue is in the calling
> >> >>> routine and not in the iBATIS invocation.
>
> >> >>> --
> >> >>> Guy Rouillier
>
> >> > --
> >> > Guy Rouillier- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/5fc5c825-aa0f-4a74-aae3-6181957983a8%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CA%2Buep2S395M51LcJJajm1AQPN34XeM%2Bs2UGibxpxeWPh2oZrPA%40mail.gmail.com.