【发布时间】:2018-12-21 15:09:36
【问题描述】:
我有一个查询,它计算 4 个表中的给定代码。我首先在 postgresql 中测试了这个查询,它按我的预期工作,所以我尝试将它翻译成 JPQL,我得到了这个错误:
java.lang.IllegalArgumentException:
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected end of
subtree [ select ((select count(*) from *.Record r where
r.codeCampaign =?1 ) + (select count(*) from *.AccountAssociationAction aaa where aaa.codeCampaign = ?1) +
(select count(*) from *.CampaignPayment cp where cp.pk.campaignCode = ?1) + (select count(*) from
*.ActionPeriodDepartment apd
where apd.id.codeCampaign = ?1))]
我不知道什么是错误的,Hibernate 的“子树的意外结束”是什么意思
postgresql 查询:
select (select count(*) from account_association_action aaa where
aaa.code_campaign = 'CAMP01') + (select count(*) from _campaign_payment cp
where cp.campaign_code = 'CAMP01') + (select count(*) from record r where
r.code_campaign ='CAMP01') + (select count(*) from action_period_department apd
where apd.code_campaign = 'CAMP01');
JPQL 查询:
@Query(value=" select (select count(*) from Record r where r.codeCampaign =?1 ) + " +
" (select count(*) from AccountAssociationAction aaa where aaa.codeCampaign = ?1) +" +
" (select count(*) from CampaignPayment cp where cp.pk.campaignCode = ?1) +" +
" (select count(*) from ActionPeriodDepartment apd where apd.id.codeCampaign = ?1)")
int countCampaignCodeUses(String campaignCode);
【问题讨论】:
-
尝试将 count(*) 替换为 count(
)
我试过了,我得到了同样的错误,它没有改变任何东西
标签: java postgresql hibernate jpql