クエリを作成する必要があり、とが必要COUNT(*)
ですHAVING COUNT(*) = x
。
CustomProjection
どこかにダウンロードしたクラスを使用する回避策を使用しています。
これは私が達成しようとしているSQLです。
select count(*) as y0_, this_.ensayo_id as y1_ from Repeticiones this_
inner join Lineas linea1_ on this_.linea_id=linea1_.id
where this_.pesoKGHA>0.0 and this_.nroRepeticion=1 and linea1_.id in (18,24)
group by this_.ensayo_id
having count(*) = 2
Projection
これは、 Hibernateクラスを使用するコードです。
critRepeticion.setProjection(Projections.projectionList()
.add( Projections.groupProperty("ensayo") )
.add( CustomProjections.groupByHaving("ensayo_id",Hibernate.LONG,"COUNT(ensayo_id) = "+String.valueOf(lineas.size()))
.add( Projections.rowCount() )
);
エラーは次のとおりです。
!STACK 0
java.lang.NullPointerException
at org.hibernate.criterion.ProjectionList.toSqlString(ProjectionList.java:50)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getSelect(CriteriaQueryTranslator.java:310)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:71)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at ar.com.cse.cseagro.controller.RepeticionController.buscarEnsayo(RepeticionController.java:101)
クラスで行をコメントすると、クエリは機能しますが、SQLでフィルターをCustomProjections
取得できません...HAVING COUNT(*)
基本的に、クエリは、マスター詳細スキーマで、詳細のリストが同時に存在するすべてのマスターレコードを取得しようとします。たとえば、「どの請求書にAとBの両方の製品があるか」を知りたい場合などです。
そのため、句に3つの項目がある場合は、IN
句を使用する必要がありますHAVING COUNT = 3
。
何かアイデアや提案はありますか?よろしくお願いします、