I am having difficulties mapping my class hierarchy to a table hierarchy. I have two tables: BASE and GENE. The BASE table has a PK column and a date column while the GENE table has a name column. Since GENE table extends BASE table you will also see the two columns of the BASE table. In my Java code I have two classes: Base and Gene where Gene extends Base. The columns of the corresponding tables are attributes of the classes. How shall I map this in Hibernate? If I use <joined-subclass> which seems to be natural, I had to specify a key column. This makes sense if the GENE table was independent as it would have to have the PK of the BASE table as a FK. But in my case the GENE table inherits the BASE table columns. If I mapped the PK of the Base class as the key for the Gene class an insertion statement into GENE would try to first insert into the BASE table and then second into the GENE table. However, what I need is a single insert statement into the GENE table.
Is there any way doing this in Hibernate?
|