-->
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: join with multiple conditions
PostPosted: Fri Jan 21, 2011 2:55 pm 
Newbie

Joined: Fri Jan 21, 2011 12:29 pm
Posts: 1
I have two tables; Person and Licenses. A Person can have many licenses. The Person mapping has a bag for Licenses and the Person class has an IList for Licenses. I want to retrieve only Person's that have Issued Licenses. This I can get to work just fine. I also only want the issued Licenses in the Person Licence list. I have tried various things but any Person objects I get back have all the Licenses for that Person in the License list not just the Issued ones.
BAG mapping for Person
Code:
<class name="Person" table="_Person"   >
    <bag name="Licenses" lazy="false" inverse="true" fetch="join" cascade="all">
      <key column="Licensee" />
      <one-to-many class="License" />
    </bag>

I also have a many to one in the licence class:
Code:
    <many-to-one name="Licensee" class="Person" lazy="false" not-null="true" fetch="join" cascade="none" />


Criteria query to get Person objects with only Issued Licenses
Code:
ICriteria crit = session.CreateCriteria(typeof(Person));
ICriteria licenceCrit = crit.CreateCriteria("Licenses", JoinType.InnerJoin);
licenceCrit.Add(Restrictions.Eq("Status", LicenseStatus.Issued));
crit.SetResultTransformer(new DistinctRootEntityResultTransformer());
var result = crit.List<Person>();


As mentioned this works fine, I only get Person objects with Issued Licenses but how can I get the Person objects to only have the Issued Licenses in their Licenses collection?

Thanks!


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.