aspose file tools
The moose likes Object Relational Mapping and the fly likes same primary key as foreign key in two table[Hibernate Mapping] Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "same primary key as foreign key in two table[Hibernate Mapping]" Watch "same primary key as foreign key in two table[Hibernate Mapping]" New topic
Author

same primary key as foreign key in two table[Hibernate Mapping]

prateek urmaliya
Ranch Hand

Joined: Sep 15, 2006
Posts: 87
Hi All,

schema

TABLE_A
=========
id_a[PK]
tx_a_desc

TABLE_B
=========
id_b[PK]
id_a[FK]
tx_b_desc

TABLE_C
=========
id_c
id_a[FK]
tx_c_desc

With id_c and id_a as composite primary key for TABLE_C

What should be the best way to map these?
It�s not normal but I can't change the schema.

I am trying something like this for now

A.java [@Table(name = "TABLE_A")]


B.java [@Table(name = "TABLE_B")]


C.java [@Table(name = "TABLE_C")]


CompositeId.java [@Embeddable]


It works but it's wrong and may break in certain cases.
Ideally nullable should be false in both the cases in A's mapping,
But when I try this I get Repeated column in mapping

Please help


this message brought to you by .... PIE! .... it's yummy! ;)
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: same primary key as foreign key in two table[Hibernate Mapping]
 
Similar Threads
Edit primary key, if it's a foreign key
Question about mapping and persisting in Hibernate/JBoss Seam
using 2 @OnetoMany annoations in one Entity Class
Populate child table foreign keys from primary table?
Outer join between 3 entities in HQL