-->
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: Query Criteria - Restrict child results in one-to-many
PostPosted: Tue Dec 23, 2008 12:49 am 
Newbie

Joined: Tue Dec 09, 2008 6:15 pm
Posts: 3
Can you add a query restriction upon a child in a one to many association where only those matching children are returned in the result set?

We have a one-to-many from an unnormalised table to itself where the parent is a collection of properties resulting from an audit event. i.e an AuditEvent (EntityLog).

Code:
AuditEvent 1 ------------------ * AuditProperties


Is it possible to filter the set returned to only include AuditProperties which meet some criteria. At the moment AuditEvents are returned complete with all audit properties if only one AuditProperty matches.

Hibernate Version: 3.2.1.ga
DB: MSSQL2000
Query:
Code:
String[] properties = new String[]{"p1, p2"};
    createAlias("propertyAudits", "pa");
    add(Restrictions.in("property", properties));

Note that the code is from a class which extends DetachedCriteria

For example:

With the following rows, I would get one audit event (expected) containing two AuditProperties (unexpected) p1 and p3.

Code:
AuditEvent    AuditProperty
1                  p1
1                  p3
3                  p3


I can post more details, but I tried to keep it simple.

Thanks,

Wayne.


Top
 Profile  
 
 Post subject: Re: Query Criteria - Restrict child results in one-to-many
PostPosted: Tue May 26, 2009 10:42 am 
Newbie

Joined: Tue May 26, 2009 10:32 am
Posts: 1
I don't want to jump on a dead thread but I ran into this and could not find much about it. So this might help others down the track.

Maybe this will make a difference for you:
createAlias("propertyAudits", "pa", CriteriaSpecification.LEFT_JOIN);

Don't ask me why it just seems to work for a similar Criteria I am doing. And it will not work if you specify INNER_JOIN or leave it out - which defaults to INNER_JOIN I think.

Not the best solution as INNER_JOIN would be preferred in the Criteria I am doing but beggars can't be choosers.


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.