2014-10-21 2 views
0

Hibernate와 그 쿼리 언어 사용하기. 나는 (SQL, Long.class) .getSingleResult() POJO에HQL에서 두 개의 select를 사용할 수 없다.

String sql = "select (select count(*) from Data v where " 
     + insuranceId 
     +" in (v.insuranceId1.id, v.insuranceId2.id, v.insuranceId3.id))" 
     +" + (select count(*) from Sat s where " 
     + insuranceId 
     +" in (s.insuranceId1.id, s.insuranceId2.id, s.insuranceId3.id))"; 

em.createQuery를 아래 쿼리를 실행하려고;

나는

2:27:47,128 ERROR [stderr] (http-/0.0.0.0:8080-5) java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected end of subtree [select (select count(*) from Data v where 991 in (v.insuranceId1.id, v.insuranceId2.id, v.insuranceId3.id)) + (select count(*) from Slot s where 991 in (s.insuranceId1.id, s.insuranceId2.id, s.insuranceId3.id))] 

그것은 카운트의 합을 포함하는 정수를 반환해야

답변

0

해보십시오 createNativeQuery에게

Object l = em.createNativeQuery(sql).getSingleResult(); 

를 조언을 주시기 바랍니다 다음과 같은 오류를 얻을.

HQL이 FROM 절없이 select를 지원하지 않는다고 가정합니다.

관련 문제