0

当我执行此代码时(JPA)

   Query q=entityManager.createQuery(SELECT mc.account_no,mc.expiry_date,
         SUM(CAST(CONCAT(mc.sign,mc.balance) AS NUMBER)),mc.moneybank_id FROM muthutcardbalance mc
     WHERE mc.account_no='20' AND mc.scheme_code='MCB' AND mc.expiry_date >= '2015-07-28' 
 GROUP BY mc.expiry_date,mc.account_no ,mc.moneybank_id ORDER BY mc.expiry_date )

我收到以下错误。我对此感到震惊。

java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Syntax error parsing the query [SELECT mc.account_no,mc.expiry_date,SUM(CAST(CONCAT(mc.sign,mc.balance) AS NUMBER)),mc.moneybank_id FROM muthutcardbalance mc WHERE mc.account_no='20' AND mc.scheme_code='MCB' AND mc.expiry_date >= '2015-07-28' GROUP BY mc.expiry_date,mc.account_no ,mc.moneybank_id ORDER BY mc.expiry_date ], line 1, column 49: unexpected token [(].

我将 JPA 2 与 EclipseLink 2.0 一起使用。

我的查询有什么问题?

但是当删除这个 SUM(CAST(CONCAT(mc.sign,mc.balance) AS NUMBER)) 它工作正常

4

1 回答 1

0

createQuery需要一个字符串作为参数,所以你应该双引号查询字符串

entityManager.createQuery("select * from dual")
于 2015-07-28T13:21:07.187 回答