2

Java Mybatis Oracle

I have following mybatis statement in xml file

<update id="updateOfferIndex" parameterType="java.util.List">
   <foreach collection="list" item="offer"  index="index"  separator=";" >
        UPDATE  offer set indx=#{offer.idx} WHERE id=#{offer.eId}
    </foreach>

I am getting following error, can any one help ?

### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

### The error may involve com.dao.linear.upsell.LinearUpsellDao.updateOfferIndex-Inline
### The error occurred while setting parameters
### SQL: UPDATE  offer set indx=? WHERE id=?   ;       UPDATE  offer set indx=? WHERE id=?
### Cause: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
d-man
  • 57,473
  • 85
  • 212
  • 296

2 Answers2

3

I resolve by insert BEGIN-END statements in this way:

BEGIN
<foreach collection="list" item="offer"  index="index"  separator=";" >
        UPDATE  offer set indx=#{offer.idx} WHERE id=#{offer.eId}
</foreach>;
END;

I hope this resolves.

Maforast
  • 257
  • 1
  • 6
  • 17
2

Looks like the last semicolon has not been appended:

    ### SQL: UPDATE  offer set indx=? WHERE id=?;       
    UPDATE  offer set indx=? WHERE id=?;

And this is coherent with the mybatis documentation about the foreach's separator:

The element is smart in that it won’t accidentally append extra separators.

Try adding a semicolon to the XML mapping:

  <foreach collection="list" item="offer"  index="index"  separator=";" >
        UPDATE  offer set indx=#{offer.idx} WHERE id=#{offer.eId}
  </foreach>
  ;
Felix Gerber
  • 1,615
  • 3
  • 30
  • 40
s17t.net
  • 157
  • 2
  • 10