I have to work with hibernate and not very sure how solve this problem, I've 2 table with a 1..n relationship like this:
------- TABLE_A ------- first_id (pk) second_id (pk) [other fields] ------- TABLE_B ------- first_id (pk)(fk TABLE_A.first_id) second_id (pk)(fk TABLE_A.second_id) third_id (pk) [other fields]
How can I manage this with Hibernate???
I don't have idea how to manage the primary key for the second table...
Use
@PrimaryKeyJoinColumn
and@PrimaryKeyJoinColumns
annotations. From Hibernate manual:There is an example which is completely similar to your case in the Hibernate reference documentation. Just before this example, you'll find the explanations. Here's the example, which matches your problem (User is table A, and Customer is table B):
Note: it would be much much simpler of you had a surrogate identifier for those two tables. Unless you're forced to deal with a legacy schema, do yourself a favor and use surrogate keys.