cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Using primary keys in expressions
Date Tue, 03 Apr 2012 16:21:52 GMT
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