openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <craig.russ...@oracle.com>
Subject Re: Opinion of statement: "The JPA specification doesn't have a way to deal with a shared primary key"
Date Sat, 17 Jul 2010 15:20:57 GMT
And I meant to add that you could also consider the two tables to be  
in an inheritance relationship in which the table with the "logical  
foreign key" maps to an Entity that is a subclass of the other Entity.

Craig

On Jul 16, 2010, at 10:39 PM, Craig L Russell wrote:

> There's no common definition for "shared primary key" that I'm aware  
> of.
>
> But let's just go and create a definition that might make sense and  
> see how JPA would deal with it.
>
> If two tables have the same type of primary key, and some values of  
> one table's PK are also values of another table's PK, this might be  
> a definition of shared primary key.
>
> You can further constrain the problem by requiring that all values  
> of one table's PK must be values of another table's PK, in effect  
> defining a logical foreign key, whether or not the logical foreign  
> key is actually declared as a foreign key.
>
> If there is no logical foreign key, then I'd agree that JPA doesn't  
> address it. A relationship has to have an "owning" side and without  
> any constraints, there cannot be an owner.
>
> If there is a logical foreign key, then there are concepts that  
> apply to modeling the tables' relationship.
>
> If you want to model the two tables as a single Entity, then you can  
> use secondary tables. This model assumes that for each row in the  
> secondary table there is a corresponding row in the primary table.  
> Fields in the Entity can be mapped to columns in the secondary table.
>
> If you want to model the two tables as two Entities, then you can  
> declare a one-to-one relationship between them. You can then  
> navigate between instances of the two Entities, and have the fields  
> of each Entity map to columns in each Entity's own primary table.
>
> Craig
>
> On Jul 16, 2010, at 6:57 PM, KARR, DAVID (ATTSI) wrote:
>
>> Would you say that the following statement is accurate or not?
>>
>> "The JPA specification doesn't have a way to deal with a shared  
>> primary
>> key."
>>
>> Isn't this what "secondary-table" addresses?  Are there other  
>> strategies
>> that apply to this?
>
> Craig L Russell
> Architect, Oracle
> http://db.apache.org/jdo
> 408 276-5638 mailto:Craig.Russell@oracle.com
> P.S. A good JDO? O, Gasp!
>

Craig L Russell
Architect, Oracle
http://db.apache.org/jdo
408 276-5638 mailto:Craig.Russell@oracle.com
P.S. A good JDO? O, Gasp!


Mime
View raw message