cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Lewis <jbryanle...@gmail.com>
Subject Re: Finding composite key using cayenne
Date Fri, 20 Apr 2012 12:36:30 GMT
Usually the recommended practice in Cayenne is not to use primary keys with
user-meaningful values.  In our shop we've learned over the years to add a
simple integer PK to join tables... simpler.

If it's is a join table, the two attributes are also foreign keys.  You
could form an expression with the related objects.  For example, we have an
EmployeeRole entity that's merely a join table between Employee and Role.
It has an "employee" relationship so we can do:

  Expression exp = ExpressionFactory.matchExp("employee",
someEmployeeObject);
  SelectQuery query = new SelectQuery(EmployeeRole.class, exp);

But if you really need to fetch with database attributes (maybe it's a
legacy table), you can.  Search for "db:" in
http://cayenne.apache.org/doc/building-expressions.html

Finally, you could expose the two PK attributes as ObjAttributes to allow
fetching without the "db:" prefix, but that can cause extra work when
creating objects. You might have to set the attributes explicity.


On Fri, Apr 20, 2012 at 6:12 AM, yunus <coolyunus1986@gmail.com> wrote:

> Hi,
> I have a table in which two attributes are primary key i.e composite.I am
> trying to access to match it with the user entered values but i am not able
> to fetch it. So can anyone tell me how to fetch composite key from database
> using cayenne?
>
> --
> View this message in context:
> http://cayenne.195.n3.nabble.com/Finding-composite-key-using-cayenne-tp3925618p3925618.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message