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.  [ 6 posts ] 
Author Message
 Post subject: How to make a query over a collection?
PostPosted: Wed Aug 11, 2004 3:34 am 
Beginner
Beginner

Joined: Mon Jul 05, 2004 9:29 am
Posts: 38
I can't find anywhere in the forum a satisfying answer on how to make a query over a collection of the following type with the criteria api:

select distinct g.*
from group as g, member as m1, member as m2
where g.groupId = m1.groupId
and g.groupId = m2.groupId;

in other words, how do I find the 'group' containing 'member1' and 'member2'?

using createCriteria() multiple times on the same entity (2 x member on 1 group) is causing a bad SqlException.

can anyone tell me if this is not supported by the current criteria api? If it is, a simple code snippet would be greatly appreciated.

thanks a lot to the brave soul who will bring me the answer!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 3:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Read the docs and use createAlias - http://www.hibernate.org/hib_docs/reference/en/html/querycriteria.html#querycriteria-associations


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 4:26 am 
Beginner
Beginner

Joined: Mon Jul 05, 2004 9:29 am
Posts: 38
The example provided in the hibernate doc is not detailed enough to understand the right way to use createAlias().

If I do something like this:

Criteria criteria = session.createCriteria(Group.class);
criteria.createAlias("members", "m1").add(Example.create(member1));
criteria.createAlias("members", "m2").add(Example.create(member2));
criteria.list();

I get the following exception:

net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) getter of Group.?

It would be nice to have better examples mixing createCriteria() and createAlias().


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 4:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, joining twice to the same association is not currently supported in Criteria API. Use HQL.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 4:53 am 
Newbie

Joined: Wed Aug 11, 2004 4:50 am
Posts: 1
As I'm also concerned by this problem, will this feature be supported in a future criteria API (hibernate 3?)

txs


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 4:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate 3.1.


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