JPA providers: why do relationships/FKs to non-PK columns work in Hibernate and EclipseLink?

EclipseLink/TopLink has always allowed foreign keys to point to any table field intentionally, as an object's primary keys didn't neccessarily need to be the pks used on the table - any unique identifier would do.

EclipseLink/TopLink has always allowed foreign keys to point to any table field intentionally, as an object's primary keys didn't neccessarily need to be the pks used on the table - any unique identifier would do. Just a guess, but using the primary key might have been one way for the JPA spec to ensure that a unique identifier is enforced, and not using the pk also has other performance implications as caching/object identity is usually only done using the primary key - so it might result in extra database hits.

Support of FK that references non-PK columns is an optional feature (and it always was so, thus there is no "JPA 1.0 syntax", my previous answer was incorrect): Support for referenced columns that are not primary key columns of the referenced table is optional. Applications that use such mappings will not be portable. However, bernate supports it: It has one more parameters named referencedColumnName.

This parameter declares the column in the targeted entity that will be used to the join. Note that when using referencedColumnName to a non primary key column, the associated class has to be Serializable. Also note that the referencedColumnName to a non primary key column has to be mapped to a property having a single column (other cases might not work).

Though, as it have been found out already, such a relationship can't be used as a part of dervied identity.

I did some experiments using bernate and EclipseLink concerning non-PK relationships. You can see how well each JPA provider maps them here: kawoolutions. Com/Technology/JPA,__and_Co.

/… – Kawu May 12 at 9:36 The point is, that 6 currently also supports multi-column non-PK relationships (which I like). – Kawu May 12 at 9:41.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions