-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate criteria a join multi columns with a subquery
PostPosted: Tue Aug 19, 2014 5:04 am 
Newbie

Joined: Mon Aug 18, 2014 10:35 am
Posts: 3
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


Top
 Profile  
 
 Post subject: Re: Hibernate criteria a join multi columns with a subquery
PostPosted: Tue Aug 19, 2014 11:48 am 
Newbie

Joined: Mon Aug 18, 2014 10:35 am
Posts: 3
No ideas ?!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.