子树 JPQL 意外结束

unexpected end of subtree JPQL

我有一个查询,它计算 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 是什么意思 "unexpected end of subtree"

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);

看起来您需要将 nativeQuery=true 添加到 @Query 注释,否则 JPA 无法理解没有 from

的查询