-->
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.  [ 3 posts ] 
Author Message
 Post subject: Criteria, Projection and select root entity
PostPosted: Mon May 22, 2006 8:31 am 
Newbie

Joined: Tue Mar 21, 2006 11:05 am
Posts: 3
Hibernate version:
3.1

i want to select the "root entity", some properties and some projection (avg/min/max) values trough the Criteria API (query is constructed at runtime so Criteria would be more convenient).

i can do folowing:

Code:
session.createCriteria(Car.class)
.setProection(Projections.projectionList()
    .add(Projection.property("owner"))
    .add(Projections.max(price)))
....


and would get a List of Arrays where index 0 is a Person.class and index 1 is a Double.

but now i need to get the Car, the Owner plus the max of the price. can i do this with the Criteria API ? or do i need to use HQL (i think select c, o, max(c.price) from Car c join fetch c.owner as o..... should do the trick)


thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 12:23 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
You now get an array with owner and max price???
How would like this to be returned?

maybe you could change your code to something like :

Code:
session.createCriteria(Car.class,"car")
.setProection(Projections.projectionList()
    .add(Projection.property("car"))
    .add(Projection.property("owner"))
    .add(Projections.max(price)))
....


Than wyou would get an array with
index 0 : Car index 1 Person, index 2 Double

Good luck!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 3:27 am 
Newbie

Joined: Tue Mar 21, 2006 11:05 am
Posts: 3
no, unfortunately this wont work since Proectsions.property is looking for mapped properties and not alias -> i will get some thing like "could not resolve property car in class Car".

i tried the HQL version (select c, max(c.price) from Car c) and this does not work because of some troubles in the group by clause (not in agregate function or groub by).


thanks for your help


pascal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.