I found this article by IBM to be helpful for understanding Hibernate
+ JPA and composite keys: 
http://www.ibm.com/developerworks/opensource/library/os-hibernatejpa/index.html

Short story: you'll have to extract your composite key into its own
class and then use that as the @Id field.

Good luck.

On Jul 1, 3:20 pm, Sean Comerford <[email protected]> wrote:
> Hours of googling have failed so I'm hoping one of you JavaPosse list
> geniuses can bail me out here :-)
>
> I have what I think is a pretty simple relationship between two DB tables.
>
> Record
> ---------
>      int seqId (key)
>      int owner (key)
>      String source (key)
>      ... other non key fields ...
>
> RecordDetails
> -------------------
>     int genId (key)
>     int seqId
>     String detailsText
>
> So record has a one to many relationship with record details based on the
> seqID.
>
> The catch here is the primary key in the record table is COMPOSITE
> consisting of seqId, owner and source (whereas RecordDetails pk is just the
> generated column genId).
>
> Starting with just having:
>
> @OneToMany
> @JoinColumn(name="seqId")
> private List<RecordDetails> details ...
>
> I've tried 18 different ways to model this in JPA / Hibernate and after much
> googling still can't get it to work.
>
> The jist of my googling seems to be that there's a limitation in JPA 1.0 in
> that ManyToOne and OneToMany relationships on foreign keys MUST have the
> same key columns.
>
> My gut feeling is there MUST be a way around this... I'm willing to use
> Hibernate annotations if necessary.
>
> Can anyone help me out?

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to