I am currently trying to map to a legacy database structure using Hibernate and have the following scenario:-
I have one table with the columns:- type, code, description where the Primary Key is type,code. Note that code is unique per type.
I have a second table which has the columns id, code, stuff where id is the Primary Key. The code is logically a foreign key onto the first table with an implied type. i.e. to join the two I need
...where table1.type = 1511 and table1.code = table2.code...
I was thinking of mapping the first table using the type as a discriminator but wondered if anyone has tried to map anything like this before. How should I best proceed.
If I use a composite key on table1, how do I then define the link to it from table2?
I also have other table which have a 'clean' foreign key onto this table using both the type and code.
Note that I only need read access to this.
|