我想将参数设置为本机查询,
javax.persistence.EntityManager.createNativeQuery
这样的事情
Query query = em.createNativeQuery("SELECT * FROM TABLE_A a WHERE a.name IN ?"); List<String> paramList = new ArrayList<String>(); paramList.add("firstValue"); paramList.add("secondValue"); query.setParameter(1,paramList);
尝试此查询会导致异常:
Caused by: org.eclipse.persistence.exceptions.DatabaseException: Internal Exception: com.MysqL.jdbc.exceptions.jdbc4.MysqLSyntaxErrorException: You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near '_binary'??\0♣sr\0‼java.util.ArrayListx??↔??a?♥\0☺I\0♦sizexp\0\0\0☻w♦\0\0\0t\0 f' at line 1 Error Code: 1064 Call: SELECT * FROM Client a WHERE a.name IN ? bind => [[firstValue,secondValue]] Query: ReadAllQuery(referenceClass=TABLE_A sql="SELECT * FROM TABLE_A a WHERE a.name IN ?")
是否可以为本机查询设置列表参数,而不是强制转换为字符串并将其附加到SQL查询?
附:我使用EclipseLink 2.5.0和MysqL服务器5.6.13
谢谢