I'm creating an order search query where I match a search literal
against several fields. If any field matches then it should return the
order. An order is created for a customer and I want to search several
fields of that customer too. It is just some experimenting with HQL.

I read the docs and my first query was:

        from Order o
        where
                (o.Code like :literal
                OR o.CustomData like :literal
                OR o.Customer.Code like :literal
                OR o.Customer.Name like :literal)

But this returns duplicate records which I think is incorrect. It
should join the records based on their relation
(Order.CustomerId=Customer.Id). So I rewrote the query into the
following that does behave correctly:

        select o
        from Order o, Customer c
        where
                o.CustomerId = c.Id
                AND(   o.Code like :literal
                        OR o.CustomData like :literal
                        OR c.Code like :literal
                        OR c.Name like :literal)

Is my first hql query incorrect or is nhibernate generating an
incorrect sql query? I expect that the result of both queries are
equal.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to