我写了以下query
。
select
count (distinct asset.assetId)
from
Asset asset
left join asset.assetTitles title
left join asset.distTypes distTypes
where
title.program.id in (:progIdParam)
and distTypes in (:lkpDistTypeId)
and asset.active = 1
and asset.isShow = 1
and asset.classification = 'Internal Use'
我用它来打电话:
private Long assetTitleListForIp = 0L;
assetTitleListForIp = (Long)entityManager
.createQuery(query)
.setParameter("progIdParam",progId)
.setParameter("lkpDistTypeId",LookupValueEnum.DIST_TYPE_INTL_PRODUCTION.getLkpId())
.getSingleResult();
如果我在eclipse控制台中触发查询并在DB中运行它,则显示count为1.但在应用程序中,对于assetTitleListForIp,它将值赋值为零。我没有得到我所做的小错误。请有人帮忙吗?
答案 0 :(得分:0)
可能你有铸造问题。 getSingleResult()
不直接转发给Long
。尝试获得如下结果:
Object countObj=entityManager.createQuery(
"select count (distinct asset.assetId) from Asset asset left join "+
"asset.assetTitles title left join asset.distTypes distTypes where "+
"title.program.id in (:progIdParam) and distTypes in (:lkpDistTypeId) "+
"and asset.active =1 and asset.isShow = 1 and asset.classification "+
"='Internal Use'")
.setParameter("progIdParam",progId)
.setParameter("lkpDistTypeId",
LookupValueEnum.DIST_TYPE_INTL_PRODUCTION.getLkpId())
.getSingleResult();
Long count=Long.valueOf(""+countObj);
assetTitleListForIp=count;
答案 1 :(得分:0)
看起来assetTitleListForIp
是字段。我怀疑你的问题与查询本身无关。可能的问题:
assetTitleListForIp
assetTitleListForIp
被执行查询的方法中的局部变量屏蔽assetTitleListForIp
。