Hi,
let me explain mu problem
I have two classes :
a super class Rent :
class Rent { Long idRent Date dateRent ... }
and a subclass CarRent :
class CarRent extends Rent { Car car String typeCar .... }
class Car { Long idCar .... }
I would like to write this SQL request using criteria (in the sub query I look for the latest rent date for each car, and then I look for rent information related to the retrieved couple (idCar, dateRent)
select * from CarRent a, Rent b, (select b.idCar, max(a.dateRent) as dateRent from Rent a, CarRent b where a.idRent = b.idRent group by (idCar) )c where a.idRent = b.idRent and b.idCar = c.idCar and a.dateRent = c.dateRent
in criteria, here it is my code
DetachedCriteria inner = DetachedCriteria.forClass(CarRent.class, "inner") .setProjection(Projections.projectionList().add(Projections.max("inner.dateRent")).add(Projections.groupProperty("inner.car")));
and
Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(Rent.getClass()).add(example); criteria.createAlias("car", "car",Criteria.INNER_JOIN,Subqueries.eq("rentDate", inner));
Any ideas how to perform a inner join between the criteria and inner (DetachedCriteria) on the two columns (idCar,rentDate) ?
Thanks guys for your help
|