-->
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: problem with 'nested' query by example
PostPosted: Thu Feb 21, 2008 10:14 am 
Newbie

Joined: Thu Feb 21, 2008 7:58 am
Posts: 2
Hello,

I'm new to Nhibernate and am attempting to use it to implement a 'search form'. I'm following section 8.5.2 in "NHibernate in action" - Dynamic Queries.
My search form includes fields from more than one domain object (ie. tables). In my case, the second domain object is a property of the first. I don't know if this is significant.

So, i'm creating example objects based on an instance of the actual objects and adding these to the criteria.

//Create Example object based on instance x.
Example exampleX = Example.Create(instanceX).IgnoreCase().EnableLike(MatchMode.Anywhere);

//Create Criteria object of type ClassX.
ICriteria criteria = session.CreateCriteria(typeof(ClassX));

//Add our Example to the criteria object.
criteria.Add(exampleX);

Example exampleY = Example.Create(instanceX.instanceY)
.EnableLike(MatchMode.Exact);

//Add to existing criteria.
criteria.CreateCriteria("XYJoin").Add(exampleY);

//List method returns objects of specified type.
criteria.List(xList);

This works ok while i supply values for properties in x and y, but returns the wrong results when i only supply values in the y object (ie. the sub-object).

I may be making an incorrect assumption about the way "query by example" works, but shouldn't i be able to return objects which contain a match in the sub-criteria?

Any help appreciated.

Chris.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 10:12 am 
Newbie

Joined: Thu Feb 21, 2008 7:58 am
Posts: 2
So,

I'm still trying to find a definitive solution to this, but have got a step further by using "CreateAlias".

e.g.
criteria.CreateAlias("ClassY", "classY");
criteria.Add(Expression.Eq("classY.Id", "ClassY"));

However, I don't want the effort of creating criterion for each of the properties of the objects (and sub-objects, and their sub-objects).

Is there a way to use Query By Example in conjunction with the alias?

Any ideas?


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.