You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Filipe Costa <ne...@gmail.com> on 2008/12/09 17:49:11 UTC

Select By ID

Hi all,

I'm creating a new project and I chosed to use Cayenne 2.4.

The thing is that I want to make a simple "Select By Id" query (auto
generated id), but it seems it is not possible! Can anyone help me?

If there are no way of selecting by an Id, how you can make basic
functionality like a table where you can delete some specific row? "Delete
USER where name = 'name'" is not a good option... neither creating a new key
column to do this.

Thanks in advance.

Cheers

Re: Select By ID

Posted by Pierre Lavignotte <pi...@gmail.com>.
Hi,

By default, Cayenne Modeler hides the primary key information of your object
entities.
You should look at the DataObjectUtils class that provide some very usefull
methods to access primary key of persistent objects and to get persistent
objects from their primary key.

For ex. if you use interger primary keys :
DataObject org.apache.cayenne.DataObjectUtils.objectForPK(ObjectContext
context, Class dataObjectClass, int pk)
int org.apache.cayenne.DataObjectUtils.intPKForObject(Persistent dataObject)

With that, you can get the ID of any persistent object and get an object by
its ID.

To delete an object, you don't have to code any SQL query, just use the API
from the DataContext class.

Pierre


On Tue, Dec 9, 2008 at 5:49 PM, Filipe Costa <ne...@gmail.com> wrote:

> Hi all,
>
> I'm creating a new project and I chosed to use Cayenne 2.4.
>
> The thing is that I want to make a simple "Select By Id" query (auto
> generated id), but it seems it is not possible! Can anyone help me?
>
> If there are no way of selecting by an Id, how you can make basic
> functionality like a table where you can delete some specific row? "Delete
> USER where name = 'name'" is not a good option... neither creating a new
> key
> column to do this.
>
> Thanks in advance.
>
> Cheers
>



-- 
Cordialement,
Pierre Lavignotte
Ingénieur Conception & Développement
http://pierre.lavignotte.googlepages.com

Re: Select By ID

Posted by Andrey Razumovsky <ra...@gmail.com>.
Have a look at DataObjectUtils.objectForPK(...) methods.
Here's a bit more detailed answer:
http://cayenne.apache.org/doc/objectidquery.html

2008/12/9 Filipe Costa <ne...@gmail.com>

> Hi all,
>
> I'm creating a new project and I chosed to use Cayenne 2.4.
>
> The thing is that I want to make a simple "Select By Id" query (auto
> generated id), but it seems it is not possible! Can anyone help me?
>
> If there are no way of selecting by an Id, how you can make basic
> functionality like a table where you can delete some specific row? "Delete
> USER where name = 'name'" is not a good option... neither creating a new
> key
> column to do this.
>
> Thanks in advance.
>
> Cheers
>