0

I have to work with Hibernate and I am not very sure how to solve this problem, I have 2 tables with a 1..n relationship like this:

-------
TABLE_A
-------
col_A1 (pk)
col_A2 (pk)
[other fields]

-------
TABLE_B
-------
col_B1 (pk) (fk TABLE_A.col_A1)
col_B2 (pk) 
col_B3      (fk TABLE_A.col_A2)
[other fields]

How can I manage this with Hibernate?

I do not have any idea how to declare a foreign key that would contain a part of primary key.

My database schema is generated from the Hibernate model.

  • share your hibernate model class – Faraz PV Dec 19 '17 at 15:20
  • how is it possible for TABLE_A and TABLE_B to have 2 (PK) – Faraz PV Dec 19 '17 at 15:22
  • @FarazPV `composite primary key` – XtremeBaumer Dec 19 '17 at 15:45
  • [this might be good source of information](https://stackoverflow.com/questions/32625410/hibernate-foreign-key-with-a-part-of-composite-primary-key?noredirect=1&lq=1) – XtremeBaumer Dec 19 '17 at 15:47
  • table structure is like – Java Techie Dec 20 '17 at 02:15
  • ------- TABLE_A ------- col_id (pk) col_key (pk) [other fields] ------- TABLE_B ------- col_id (pk) (fk TABLE_A.col_id) col_key (pk) col_parentkey (fk TABLE_A.col_key) [other fields] TABLE_A is one to many relation with TABLE_B. TABLE_A.id and TABLE_A.key are primary key (composite key). TABLE_B.id and TABLE_B.key are primary key (composite key). At the same time TABLE_B.parentkey is same as TABLE_A.key and TABLE_B.id is same as TABLE_A.id – Java Techie Dec 20 '17 at 02:21
  • It has not been possible in Hibernate for years. There is an open bug for that that has not been assigned for ages. https://hibernate.atlassian.net/browse/HHH-6221 – Jagger Dec 21 '17 at 13:01

0 Answers0