-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria API, ALIAS_TO_ENTITY_MAP, controlling shown Aliases
PostPosted: Wed Apr 30, 2008 5:55 pm 
Newbie

Joined: Tue May 10, 2005 6:15 am
Posts: 4
I have three entities like:
Code:
class A {
  List<B> blist;
}

class B {
  List<C> clist;
}

class C {
  int size;
}



So I have one to many relations between:
- A and B
- B and C

I want to select all pairs (A,B) having C.size = 5.

I want to do that using criteria API.

I did :
Code:
hc = session.createCriteria(A.class, "a");
hc.createCriteria("a.blist", "b");
hc.createCriteria("b.clist", "c");
hc.add(Restrictions.eq("c.size", 5);

hc.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

Even if i include c only for restricting the query, the system gives pairs
<A,B,C> but i want to get only distinct pairs <A,B>

Is there a way to exclude C from "select " ?

Right now I'm using DetachedCriteria:
- Subselect.exists
- in

but both seems ineficient in terms of performance and the code is not readable.

Any other options?


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

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.