Re: Queries based on relationship size

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Feb 21 2008 - 08:55:56 EST

  • Next message: Borut Bolčina: "Re: How to migrate from Hibernate to Cayenne?"

    EJBQL query with outer joins should help:

    1. select c from Customer c JOIN c.orderHistory

        (inner join filters customers with Orders, so this is like a
    regular SelectQuery)

    2. select c from Customer c LEFT JOIN c.orderHistory d WHERE d is null

        (outer join combined with the WHERE clause should allow fetching
    customers with no orders)

    Two caveats: we still need to add pagination support per CAY-963; I
    may have taken a few _temporary_ shortcuts in the EJBQL parser that
    may cause trouble with flattened relationships, so let me know if you
    run into problems.

    Andrus

    On Feb 21, 2008, at 3:05 AM, Kevin Menard wrote:

    > Greetings,
    >
    > I'm running into a little difficulty performing a query that I think
    > comes up often enough that it should be fairly straightforward.
    >
    > I have a schema similar to the following:
    >
    > Customer <--- BillingInfo <--- Order
    >
    > I've mapped the read-only relationship "orderHistory" from Customer to
    > Order.
    >
    > Now I'd like to perform two queries. One for customers with orders
    > and
    > one for customers without. I'd rather not filter in the app itself
    > because I'd like to paginate the result lists.
    >
    > Is there a way to do this without resulting to an SQLTemplate query?
    >
    > Thanks,
    > Kevin
    >
    > --
    > Kevin Menard
    > Servprise International, Inc.
    > Remote reboot & power control for your network
    > www.servprise.com +1 508.892.3823 x308
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Thu Feb 21 2008 - 08:56:31 EST