cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aristedes Maniatis <>
Subject Re: Primary Keys
Date Thu, 01 Nov 2012 22:44:10 GMT
On 2/11/12 6:35am, Garth Keesler wrote:
> Can the PK as specified in the DBEntity be different than the PK actually specified in
the schema? I ask because I use DB-generated integer sequences as the primary keys which are
never used in the software. The software uses an abbreviated form of the vendor name that
is forced to be unique within the table. Would it make more sense to specify that the shortened
name is the "real" PK in the definition of the DBEntity (which is hand-created, not extracted
from the schema)? FYI, this column is also used in may foreign keys. Speaking of FKs, if I
specify a relation in the DBEntity, should it share the name of the FK specified in the schema
or are they unrelated?

I suggest that you map Cayenne's concept of the PK to the real PK since that is what you'll
want to use for FK joins from other tables. Then just create a normal field for your vendor
code and add validation to keep it unique. Making the vendor code the PK in any way is likely
to cause lots of pain down the track when one of your vendors changes names and wants a new

One of the reasons Cayenne hides the PK from the Java entities by default is that it is almost
never a good idea to expose the PK to users of the software.


Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

View raw message