-->
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.  [ 4 posts ] 
Author Message
 Post subject: Complex "group by" using Criteria
PostPosted: Tue Sep 27, 2005 9:26 am 
Beginner
Beginner

Joined: Fri Sep 24, 2004 7:15 am
Posts: 40
Hi,

I'm using the Criteria API as I have dynamic constraints within my object. But also I need to include a "group by" clause which makes reference to nested properties in my object.

I mean, I have:

Code:
session.createCriteria(Myclass.class).setProjection(Projections.groupProperty("field.subfield.subsubfield"))


so as it can be seen I want to indicate an object within an object within another object. But it doesn't work. I get the following error:

Code:
could not resolve property: subfield.subsubfield


Using HQL I imagine it could be:

Code:
select ...
from Myclass
....
group by field.subfield.subsubfield


But I can't use HQL.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 9:34 am 
Newbie

Joined: Sat Jul 23, 2005 8:31 am
Posts: 18
try to create an alias

Code:
session.createCriteria(Myclass.class).createAlias("subfiled", "sf")
    .setProjection(Projections.groupProperty("sf.subsubfield"))


i didn't try it so im not sure


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 9:44 am 
Beginner
Beginner

Joined: Fri Sep 24, 2004 7:15 am
Posts: 40
Hi chrigi,

Thanks for your hint, but it doesn't work. The aliases work for the rest of the Criteria criterion, but not for using them in the projections (at least as far as I know).

Any alternatives?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 9:59 am 
Beginner
Beginner

Joined: Fri Sep 24, 2004 7:15 am
Posts: 40
I finally solved it!

Yes, you were right with using aliases, but my problem was the way I was using them. It seems that you cannot use an alias directly inside the projection, but you have at least to indicate one member of the alias.

For example, imagine you have an alias "sf". You can't do:

Code:
groupProperty("sf")


but you can do:

Code:
groupProperty("sf.something")


So forum admins please give my positive vote to chrigi ;-)


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