I would like to use the sleep criteria criteria object as a subquery for the second criterion, for example:
DetachedCriteria latestStatusSubquery = DetachedCriteria.forClass(BatchStatus.class);
latestStatusSubquery.setProjection(Projections.projectionList()
.add( Projections.max("created"), "latestStatusDate")
.add( Projections.groupProperty("batch.id"))
);
DetachedCriteria batchCriteria = DetachedCriteria.forClass(BatchStatus.class).createAlias("batch", "batch");
batch.add( Property.forName( "created" ).eq( latestStatusSubquery ) );
The problem is that adding groupProperty automatically adds this property to the select clause in the subquery request, and I cannot find a way to stop this.
The result, of course, is a database error, because the subquery returns too many values.
Does anyone know about this?
source
share