Ok I see the confusion. My second message could be been clearer in saying:
"As well as all SpecialOrders I want my result set to inlcude Orders that
are not SpecialOrders but do have a non-deleted Person."
I'm building the JIRA test case now.
I tried the HQL solution you suggested but I think that shows another bug.
If you use your HQL the generated sql is this:
select order0_.Id as Id0_, order0_.PersonID as PersonID0_, order0_.Class as
Class0_
from Orders order0_, Person person1_
where (order0_.Class='SpecialOrder' )or(person1_.IsDeleted=0 and
order0_.PersonID=person1_.Id)
As you can see this is very different from the sql I expected. There is no
left outer join and as a result the query returns seven results not four
(the Special orders are returned N times where N is the number of Rows in
the Person table)
Any thoughts would be appreciated.
Thanks
Jon
On Mon, Sep 22, 2008 at 1:16 PM, Ken Egozi <[EMAIL PROTECTED]> wrote:
> I still do not follow.
> on the first message:
>
>> all Orders where the order is of type special order or where the
>> Order.Person is not deleted
>>
>
> on the second message:
>
>> I want my result set to inlcude Orders that are not SpecialOrders but do
>> have a non-deleted Person.
>
>
> the reasoning from the table is like in the first message
>
> anyway, the NRE looks like a bug, and we'd appreciate a full stack trace
> and a JIRA issue so we could look it into.
>
> meanwhile, does using hql suits you?
>
> select o
> from Orders o
> where o is SpecialOrder or o.Person.IsDeleted = 0
>
> btw, why did you need a subcriteria?
> I guess that
> ICriteria criteria = session.CreateCriteria(typeof (Order))
> .CreateAlias("Person", "p")
> .Add(Restrictions.Or(
> Property.ForName("class").Eq(typeof(SpecialOrder)),
> Restriction.Eq("p.IsDeleted", false)
> )).List();
> should have worked right?
>
>
>
> On Mon, Sep 22, 2008 at 10:15 PM, Jon Palmer <[EMAIL PROTECTED]> wrote:
>
>> sorry typo in my previous email, should be:"I would expect to get back
>> the first 4 orders but not order 5. "
>>
>>
>> On Mon, Sep 22, 2008 at 12:12 PM, Jon Palmer <[EMAIL PROTECTED]>wrote:
>>
>>> Ok I will file the JIRA ticket. I'm not sure how I would
>>> use CreateCriteria(typeof(SpecialOrder)). I want my result set to inlcude
>>> Orders that are not SpecialOrders but do have a non-deleted Person.
>>> Suppose the left join of the Orders and Parties table looks like this
>>>
>>> Order.ID | Order.Class | Order.PersonID | Person.ID | Person.IsDeleted
>>>
>>> 1 | SpecialOrder | 1 | 1 |
>>> 0
>>> 2 | SpecialOrder | 2 | 2 |
>>> 1
>>> 3 | SpecialOrder | null | null |
>>> null
>>> 4 | Order | 1 | 1 |
>>> 0
>>> 5 | Order | 2 | 2 |
>>> 1
>>>
>>>
>>> I would expect to get back the first 4 orders but not order 1.
>>>
>>> Thanks
>>> Jon
>>>
>>> On Mon, Sep 22, 2008 at 12:04 PM, Ayende Rahien <[EMAIL PROTECTED]>wrote:
>>>
>>>> NRE is a bug, please create a test case and add it to the JIRA.
>>>> In the meantime, you can use CreateCriteria(typeof(SpecialOrder))
>>>>
>>>>
>>>> On Mon, Sep 22, 2008 at 9:59 PM, Jon Palmer <[EMAIL PROTECTED]>wrote:
>>>>
>>>>> I would appreciate some help combining logical expressions in criteria
>>>>> queries.
>>>>> My toy object model is three classes
>>>>>
>>>>> Order and a subclass SpecialOrder
>>>>> Person
>>>>>
>>>>> each Order has a Person property. I'm trying to do a query for all
>>>>> Orders where the order is of type special order or where the Order.Person
>>>>> is
>>>>> not deleted. I've tried this:
>>>>>
>>>>> DetachedCriteria detached= DetachedCriteria.For(typeof(Person), "p")
>>>>> .Add(Property.ForName("p.IsDeleted").Eq(false));
>>>>> ICriteria criteria = session.CreateCriteria(typeof (Order))
>>>>> .Add(Restrictions.Or(
>>>>> Property.ForName("class").Eq(typeof(SpecialOrder)),
>>>>> Property.ForName("Person").Eq(detached)
>>>>> )).List();
>>>>>
>>>>>
>>>>> but I get a null Reference exception in:
>>>>> "NHibernate.Criterion.SubqueryExpression.InitializeInnerQueryAndParameters(ICriteriaQuery
>>>>> criteriaQuery)"
>>>>>
>>>>>
>>>>> Any thoughts on how to get this kind of query right?
>>>>>
>>>>> Thanks
>>>>> Jon
>>>>>
>>>>>
>>>>> P.S. I'm expecting that the sql generated should look something like
>>>>> this:
>>>>>
>>>>> select .... from Orders o, left out join Persons p on o.PersonID = p.ID
>>>>> where
>>>>> o.Class = 'SpecialOrder' or (o.PersonID is not null and p.IsDeleted =
>>>>> 0)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>>
>
>
> --
> Ken Egozi.
> http://www.kenegozi.com/blog
> http://www.musicglue.com
> http://www.castleproject.org
> http://www.gotfriends.co.il
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---