You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Oksana Peterburgskaya <ok...@amphorainc.com> on 2016/09/14 20:32:14 UTC

Re: Fetching a list of objects from a list of primary keys

Hello,
I'm currently working on  a case related to this post where I try to fetch a list of objects based on a list of primary keys. The difference for me is that the primary key consists of multiple fields id db. If I try to use ObjectForPK(), it accepts such multi-park PKs. However, if I try to put multiple multip-part PK in input maps for ObjectForPK(), ObjectForPK() but only returns the first object, not all of them.

I can't really user ExpressionFactory.InDBExp() the way it is suggested in the post. Are there any other solutions? I really need to do get all objects in one query otherwise we are hit with db-related performance issues.

Thank you very much,
Oksana Peterburgskaya

http://grokbase.com/t/cayenne/user/164cdjb5ts/fetching-a-list-of-objects-from-a-list-of-primary-keys
Confidentiality Notice: This e-mail and accompanying documents contain confidential information intended for a specific individual and purpose. This e-mailed information is private and protected by law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, or distribution, or the taking of any action based on the contents of this information, is strictly prohibited.

Re: Fetching a list of objects from a list of primary keys

Posted by John Huss <jo...@gmail.com>.
You can use ExpressionFactory.matchDbExp("pk1",
val1).and(ExpressionFactory.matchDbExp("pk2", val2))

Then assemble the resulting AND expressions into a list of OR expressions
using ExpressionFactory.or()

       pk1 = val1 AND pk2 = val2
OR  pk1 = val3 AND pk2 = val4
OR  pk1 = val5 AND pk2 = val6



On Wed, Sep 14, 2016 at 3:41 PM Oksana Peterburgskaya <
oksana.Peterburgskaya@amphorainc.com> wrote:

> Hello,
> I'm currently working on  a case related to this post where I try to fetch
> a list of objects based on a list of primary keys. The difference for me is
> that the primary key consists of multiple fields id db. If I try to use
> ObjectForPK(), it accepts such multi-park PKs. However, if I try to put
> multiple multip-part PK in input maps for ObjectForPK(), ObjectForPK() but
> only returns the first object, not all of them.
>
> I can't really user ExpressionFactory.InDBExp() the way it is suggested in
> the post. Are there any other solutions? I really need to do get all
> objects in one query otherwise we are hit with db-related performance
> issues.
>
> Thank you very much,
> Oksana Peterburgskaya
>
>
> http://grokbase.com/t/cayenne/user/164cdjb5ts/fetching-a-list-of-objects-from-a-list-of-primary-keys
> Confidentiality Notice: This e-mail and accompanying documents contain
> confidential information intended for a specific individual and purpose.
> This e-mailed information is private and protected by law. If you are not
> the intended recipient, you are hereby notified that any disclosure,
> copying, or distribution, or the taking of any action based on the contents
> of this information, is strictly prohibited.
>