在jpa查询中解析错误得到解析错误

时间:2013-05-19 22:11:54

标签: jpa

StringBuffer query = new StringBuffer();
query.append("SELECT e FROM DBMGPersonMetaData e WHERE
    e.moduleUniqueId.extension= ?1 AND e.ConsType ");

query.append("IN ( SELECT  CASE WHEN " +"INSTR(p.description, ' ') = 0  "+
"   THEN SUBSTR(p.description,1)   "+ " WHEN INSTR(p.description, ' ') !=0 "+
"   THEN SUBSTR(p.description,1,INSTR(p.description, ' ')-1)  END"+ " AS ee  FROM DBProjectMetaData p WHERE p.projectUniqueId.extension= ?2");
dbModuleperson = (DBMGPersonMetaData) 
entityManager.createQuery(query.toString()).setParameter(1,"12").
setParameter(2,"12").getSingleResult();

1 个答案:

答案 0 :(得分:0)

要在native SQL query中运行JPA,您应该使用此方法:

entityManager.createNativeQuery(query.toString());

您使用的方法(createQuery)接受JPQL查询或CriteriaQuery