cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ramiro Aparicio <ramiro.apari...@prot-on.com>
Subject Re: Using primary keys in expressions
Date Tue, 03 Apr 2012 16:32:10 GMT
As I see it that will indeed use a query per user to create the 
expression, as every objectForPk will need one query to at least 
determine if the user exist or not and retrieve the user object, wich is 
just what I was trying to avoid.


El 03/04/2012 18:21, Andrus Adamchik escribió:
> Actually here is a more terse syntax:
>
> User u2 = Cayenne.objectForPk(context, User.class, 2);
> User u5 = Cayenne.objectForPk(context, User.class, 5);
>
> Expression e = ExpressionFactory.matchAnyExp(u2, u5);
>
>
> On Apr 3, 2012, at 7:19 PM, Andrus Adamchik wrote:
>
>> Don't forget that Cayenne analog of matching against a PK in DB is matching against
the Object itself!
>>
>> User u2 = Cayenne.objectForPk(context, User.class, 2);
>> User u5 = Cayenne.objectForPk(context, User.class, 5);
>>
>> Expression e2 = ExpressionFactory.matchExp(u2);
>> Expression e5 = ExpressionFactory.matchExp(u5);
>>
>> Expression e = e2.orExp(e5);
>>
>> Andrus
>>
>>
>> On Apr 3, 2012, at 6:43 PM, Michael Gentry wrote:
>>
>>> Hi Ramiro,
>>>
>>> By default, Cayenne does not map PKs into Java objects because they
>>> are considered database artifacts.
>>>
>>> What is the source of your idUser values (the 2,5)?  If external to
>>> your application, you can always manually add idUser back into your
>>> ObjEntity in Cayenne Modeler.
>>>
>>> If the source is really internal, you might want to consider matching
>>> against user names or objects or other attributes.
>>>
>>> mrg
>>>
>>>
>>> On Tue, Apr 3, 2012 at 11:18 AM, Ramiro Aparicio
>>> <ramiro.aparicio@prot-on.com>  wrote:
>>>> I am trying to do what I thought it should be an easy query
>>>>
>>>> SELECT * FROM Users WHERE idUser IN (2,5)
>>>>
>>>> The problem is that it seems that the primary key of tables is somewhat of
a
>>>> special column that is not allowed to be used in expressions as I get
>>>> Can't resolve path component: [User.idUser].
>>>>
>>>> My current piece of code is:
>>>>
>>>> Expression where = ExpressionFactory.inExp(ID_USER_PK_COLUMN, userids);
>>>> SelectQuery query = new SelectQuery(User.class, where);
>>>> @SuppressWarnings("unchecked")
>>>> List<User>  dbUsers = dataContext.performQuery(query);
>>>>
>>>> I know I can use objectForPK for every id but that doesn't seem to be too
>>>> sensible, so can anyone please point me another way to get the user list
in
>>>> just 1 query?
>>>>
>>>> Thanks in advance
>>>> Ramiro
>>
>


Mime
View raw message