Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 子树JPQL意外结束_Java_Postgresql_Hibernate_Jpql - Fatal编程技术网

Java 子树JPQL意外结束

Java 子树JPQL意外结束,java,postgresql,hibernate,jpql,Java,Postgresql,Hibernate,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.cod

我有一个从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);

看起来您需要将
nativeQuery=true
添加到
@Query
注释中,否则JPA在没有
的情况下无法理解来自

的查询,请尝试用count()替换count(*),我尝试过,但我得到了相同的错误,它没有改变任何内容感谢您的回答,这正是我最终所做的