cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aristedes Maniatis <>
Subject Re: Class Relation vs Foreign Key
Date Tue, 06 Nov 2012 11:33:26 GMT
On 6/11/12 9:05pm, Garth Keesler wrote:
> Should/must the name used when defining a relation between classes in Modeler be the
same as the name used when defining a foreign key in the database? As a follow-up, does Cayenne
even use FKs or does it depend on its own class definitions and indexes in the database to
accomplish this?  This is in hand-coded class definitions instead of generating the classes
from the database schema. If FKs are used, how is the correlation between relations and foreign
keys made or does Cayenne depend on the database software to use the appropriate foreign key

A Foreign Key in a database is usually nothing more than an index with a constraint. That
is, there is nothing special about the key other than some constraint to prevent invalid data
creeping in.

Cayenne uses whichever keys you define in the model in order to define its joins and it doesn't
know anything about the constraints you added to the SQL database. You don't need to tell
the database about these keys at all, although it is usually a good idea to have validation
(constraints) both in Cayenne and in the database itself. And of course if you don't have
an index in the database at all, the joins may be quite slow.

Remember that when you start using inheritance in Cayenne, the concept of a join between Java
objects will no longer map to a simple join between a FK and PK in two tables. But Cayenne
takes care of everything for you.


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

View raw message