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: ICriteria help
PostPosted: Fri Jun 23, 2006 5:46 am 
Newbie

Joined: Thu Apr 13, 2006 9:26 am
Posts: 9
Hello,

I need some help on building a ICriteria query. Suppose I have:

Code:
class A
{
    public string label;
}

class B
{
    public A a;
}

Now I want to select all B objects where (a is null) or (a is not null but a.label is null) or (a is not null and a.label is different than 'value').

Basically I want something like this but this does not compile as ICriteria is not a ICriterion:

Code:
session.CreateCriteria(typeof(B)).Add(Expression.Or(
    Expression.IsNull("a"),
    Expression.Or(
        session.CreateCriteria(typeof(A)).Add(Expression.IsNull("label")),
        session.CreateCriteria(typeof(A)).Add(Expression.Not(Expression.Eq("label", "value)))
    )
));

Anybody knows how I am supposed to do this?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 8:38 am 
Newbie

Joined: Thu Apr 13, 2006 9:26 am
Posts: 9
Ok. I have made some progress. I will be more precise with what I want to do:

Code:
class A
{
}

class B
{
    A a;
}

class C
{
   List<B> b;
}


I want to select all the C's that do not have a B element where a=a1. Therefore I have three criterias:
- b is empty
- for an instance B of b, either b.a is null or b.a is different from a1

I am doing this:
Code:
ICriteria cc = session.CreateCriteria(typeof(C));
ICriteria cb = cc.CreateCriteria("b");
cb.Add(Expression.Or(
   Expression.IsNull("a"),
   Expression.Not(Expression.Eq("a", a1))));
return cc.List();


When I look at the generated SQL, the problem is that NHibernate generates an "inner join" select from C to B. Therefore the criteria "b is empty" cannot be matched as this would require a "left outer join". I tried to add "cc.SetFetchMode("b", FetchMode.Join);" before calling List() but this does not change anything... I even tried to change this in the mapping file (just for testing purposes) to no avail.

Anyone has more hints on this?

Thanks,


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.