使用 Open JPA 2.0,数据库是 DB2 9.7。对于类似的查询SELECT COUNT(1) FROM USER WHERE FNAME := fname
,JPA 将查询转换为SELECT COUNT(CAST(? AS BIGINT)) FROM TABLENAME
. 如何避免 CAST 到 BIGINT?
下面的代码示例:
query = entityManager.createNamedQuery("qry.checkuser");
query.setParameter("fname", fname);
Long count = (Long)query.getSingleResult();