JPA - Simple DB schema, complicated JPA configuration...
Hi,
I have 2 tables:
Code:
TABLE 1 (
CODE VARCHAR(8) -- primary key
...
)
TABLE2 (
TABLE1_CODE VARCHAR(8), -- primary key, foreign key 1, foreign key 2
CODE VARCHAR(10), -- primary key
PARENT_CODE VARCHAR(10) -- foreign key 2
)
The primary key of TABLE2 is TABLE1_CODE + CODE.
TABLE2 is linked to TABLE1 (TABLE1.CODE = TABLE2.TABLE1_CODE). It is the first foreign key.
TABLE2 can have a parent, but the parent must have the same TABLE1_CODE than his children. Then the TABLE1_CODE column is part of the primary key, and also part of the foreign key (to link with the TABLE2 parent).
TABLE1_CODE is part of the primary key, is a foreign key, and is part of a second foreign key.
I do not want to create a sedonc TABLE1_CODE column.
How can I define my pojos and how can I configure JPA / Spring-data-jpa to manage this DB schema ?
If you are a JPA master, feel free to help me. ;o)