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: Could use some help going from HQL to Criteria
PostPosted: Tue Aug 15, 2006 3:30 pm 
Newbie

Joined: Sat Mar 11, 2006 4:15 pm
Posts: 15
I need to translate the following query (which is tested and works) to use Criteria:

select distinct(c)
from Card c
join c.categories cat
join cat.allParents category
join category.allChildren child
join child.cards card
where c.id = card.id
and category = ?)

So far I have:

return getSession().createCriteria(Card.class, "c")
.setProjection(Projections.distinct(Projections.property("c")))
.createAlias("c.categories", "cat")
.createAlias("cat.allParents", "category")
.createAlias("category.allChildren", "child")
.createAlias("child.cards", "card")
.add(eqProperty("c.id", "card.id"))
.add(eq("category.id", cat.getId()));

which returns the exception "cannot resolve property: c of com.domain.Card"

if I take out the projection it works fine. anyone know of how to do distinct in the projection? Thanks.


Top
 Profile  
 
 Post subject: think i got a fix
PostPosted: Tue Aug 15, 2006 4:27 pm 
Newbie

Joined: Sat Mar 11, 2006 4:15 pm
Posts: 15
Found tihs in another post: can use .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

seems to be working well so far.


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.