Find EJB where primary key in a collection of ids - Weblogic

This is a discussion on Find EJB where primary key in a collection of ids - Weblogic ; Hello. I am struggling to find a solution to a simple problem. I have a collection of entity bean primary keys, and I need a query that fetches the collection of entity beans matching the keys, where the keys are ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Find EJB where primary key in a collection of ids

  1. Find EJB where primary key in a collection of ids

    Hello. I am struggling to find a solution to a simple problem. I have a
    collection of entity bean primary keys, and I need a query that fetches the
    collection of entity beans matching the keys, where the keys are passed as
    arguments to the query. For example, I want something like this:

    SELECT OBJECT(o)
    FROM MyObjectSchema o
    WHERE o.guid IN (?1)

    Where ?1 is a comma delimited list identifiers: "foo,bar,baz,whatever", or
    an array/collection of strings.

    WebLogic wraps the argument in quotes so that the enitre list of identifiers
    is interpreted as a single identifier. Is there some way to make WebLogic
    interpret the argument as a comma delimited list of identifiers? Is there
    another idiom by which a collection of entities may be fetched by their
    primary keys? The only workaround I know is to fetch the objects in batches
    and then aggregate the batches into a single batch:

    SELECT OBJECT(o)
    FROM MyObjectSchema o
    WHERE (o.guid = ?1 OR o.guid = ?2 OR o.guid = ?3 OR . . . )

    Any ideas?

    Thanks, Dave



  2. Re: Find EJB where primary key in a collection of ids


    If the number of PKs is fixed (not likely), then you can use the condition:

    WHERE pk IN (?1, ?2, .. ?n)

    If the number PKs is not fixed and if their values can be represented as
    string or numeric literals then one way to do it might be to
    write a small java routine that will take the collection of pks and
    generate an EJB QL query that is then passed to a DynamicQuery (see docs
    on Dynamic Queries).

    -thorick

  3. Re: Find EJB where primary key in a collection of ids

    I was afraid that would be the answer. Thanks for your help. Do you know if
    future versions of the EJB QL spec will support something like this?

    Dave

    "thorick" wrote in message
    news:3fd94238$1@newsgroups.bea.com...
    >
    > If the number of PKs is fixed (not likely), then you can use the

    condition:
    >
    > WHERE pk IN (?1, ?2, .. ?n)
    >
    > If the number PKs is not fixed and if their values can be represented as
    > string or numeric literals then one way to do it might be to
    > write a small java routine that will take the collection of pks and
    > generate an EJB QL query that is then passed to a DynamicQuery (see docs
    > on Dynamic Queries).
    >
    > -thorick




  4. Re: Find EJB where primary key in a collection of ids


    Hi,

    As far as I know, there are no proposals to add Collection parameters
    to EJB QL. I would guess that the reason is that while EJB QL has
    the appearance of a language that deals with Objects, the reality is
    that actual implementations will have to be built on top of popular
    and widely used SQL engines (that don't support this).


    -thorick



+ Reply to Thread