0

Why do I get this error from MyBatis 3?

Caused by: java.sql.SQLSyntaxErrorException: unexpected token: < required: (

This is my SQL:

SELECT * FROM GC0101.AGENT_POOL_CLIENT_ASSIGNMENT WHERE GO_CD = ? 
AND ASSIGNMENT_STATUS_CD IN %lt;foreach item="item" index="index" 
collection="assignmentStatusCd" open="(" separator="," close=")"%gt; 
? %lt;/foreach%gt;

created from this query:

@Select("SELECT * FROM GC0101.AGENT_POOL_CLIENT_ASSIGNMENT WHERE GO_CD = 
#{generalOfficeCd, jdbcType=CHAR} AND ASSIGNMENT_STATUS_CD IN " +
"&lt;foreach item=\"item\" index=\"index\" collection=\"assignmentStatusCd\" 
open=\"(\" separator=\",\" close=\")\"%gt; #{item, jdbcType=CHAR} %lt;/foreach%gt;") 
Bogdan
  • 23,890
  • 3
  • 69
  • 61
jimmy
  • 165
  • 1
  • 6
  • 18
  • 1
    Could you include more information on how are you building that SQL? Are you sure that your log message is related to your posted information? – Leandro Carracedo Jan 03 '15 at 05:03

1 Answers1

0

If that is indeed your annotation value then it will not work because you are trying to include an XML statement inside the annotation's only value which is not parsed for XML elements, it's taken "as it is".

You can find a possible solution in this post: How to use Annotations with iBatis (myBatis) for an IN query? (see the @Select("<script>...") example in LordOfThePigs' answer - works with the latest MyBatis version) or try with a @SelectProvider annotation. See the Mybatis 3 API docs for more details and this note as an advice:

Java Annotations are unfortunately limited in their expressiveness and flexibility. Despite a lot of time spent in investigation, design and trials, the most powerful MyBatis mappings simply cannot be built with Annotations – without getting ridiculous that is.

Community
  • 1
  • 1
Bogdan
  • 23,890
  • 3
  • 69
  • 61
  • I will investigate "@SelectProvider". Thank you. – jimmy Jan 05 '15 at 16:19
  • @jimmy: If you are using the latest MyBatis version, `@Select(" – Bogdan Jan 05 '15 at 16:23