使用Hibernate及其查询语言。我尝试在POJO中执行以下查询
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(sql,Long.class).getSingleResult();
我收到以下错误
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 :(得分:0)
尝试createNativeQuery
Object l = em.createNativeQuery(sql).getSingleResult();
它应该返回包含计数总和的整数。
我认为HQL不支持select without FROM子句。