鉴于此分离查询:
DetachedCriteria notExistInCriteria = DetachedCriteria.forClass(ReportTelephonyEvent.class, "r2");
notExistInCriteria.add(Restrictions.eq("child", child));
notExistInCriteria.add(Restrictions.eqProperty("countryCode", "r1.countryCode"));
notExistInCriteria.add(Restrictions.eqProperty("phonenumber", "r1.phonenumber"));
notExistInCriteria.add(Restrictions.or(Restrictions.lt("startTime", start), Restrictions.gt("startTime", end)));
notExistInCriteria.setProjection(Projections.property("phonenumber"));
我现在设置了Projection“phonenumber”,但是我想将它设置为1,这样输出查询将是这样的':
SELECT 1 FROM bpr_report_telephony_event .............
如何设置Projection以使Hibernate在选择列中只有“1”?
答案 0 :(得分:0)
用Projections.sqlProjection(“1”)替换Projections.property(“phonenumber”)应该这样做。
答案 1 :(得分:0)
为了得到“1”作为投影的结果,你可以这样做:
notExistInCriteria.setProjection(Projections.sqlProjection("1", new String[]{}, new Type[] { IntegerType.INSTANCE })