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: Criteria Search By Association Question...
PostPosted: Sat Dec 23, 2006 1:24 pm 
Newbie

Joined: Fri Dec 22, 2006 6:44 pm
Posts: 7
NHibernate Version: 1.0.3

For example...

I have a class called Location that has a many-to-one relationship with class Product. Class Product also is the base class for two subclasses, Form and Publication (two types of products). I am able to perform a search via criteria like the following in order to get a collection of locations that point to products of type Form (this is just psuedo code) ...

results = session.createcriteria(Location).createcriteria(Product).Add(New Expression.EqExpression("class", "Form").List()

However, what would I have to do in order to find the locations that point to products of type Form whose Form specific properties are of a certain value? I would think that something like this ...

results = session.createcriteria(Location).createcriteria(Product).Add(New Expression.EqExpression("class", "Form").Add(New Expression.EqExpression("FormSpecificProperty", "value").List()

... would produce an error because "FormSpecificProperty" would belong to the Form class and not Product.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 24, 2006 9:58 am 
Newbie

Joined: Fri Dec 22, 2006 6:44 pm
Posts: 7
Any help would be greatly appreciated :-)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 24, 2006 3:49 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Thinking is overrated, you should try it and see what is happening.
At any rate, the way I would do it is something like:

Code:
DetachedCriteria form = DetachedCritaria.For(typeof(Form))
.Add(Expression.Eq("FormSpecifc", "val"))
.Add("this.Location", "loc");

session.CreateCriteria(typeof(Location),"loc")
.Add( Subqueries.Exists(form) );



Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 25, 2006 2:13 pm 
Newbie

Joined: Fri Dec 22, 2006 6:44 pm
Posts: 7
That's definitely the approach that I would like to take, but is this feature available in 1.0.3? I didn't think it was.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 25, 2006 2:16 pm 
Newbie

Joined: Fri Dec 22, 2006 6:44 pm
Posts: 7
The DetachedCriteria feature that is :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 25, 2006 2:41 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
No, that is only for 1.2.


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.