views:

95

answers:

3

I have a entities as:

  • BaseEntity --> Which contains user login info like createdBy, createdTime, EditedBy, editedTime
  • Employee --> which contains employee information like name, address, etc...
  • RegularEmployee --> which contains salary, bonus tht kind of fields and
  • ContactEmployee --> which contains HourlyRate, contactPeriod etc....

My inheritance structure is

alt text

How to design database structure in this case considering all the tables have id and version fields (all tables should at least have these two fields).

A: 

Chapter 9. Inheritance mapping

i've used the "Table per class" model. it works well for what i'm doing.

the discriminator column tells hibernate which subclass to instantiate, and subclasses can have fields that other subclasses don't have, but the table needs to have all columns (null for some rows obviously).

pstanton
A: 

hi, the answer given by 'pstanton' is good and upto the mark.. but there is one more way.. same as u implement inheritance in Java. refer the following mapping for you answer

<union-subclass name="Employee" extends="BaseEntity" table="tb_emp" >
</union-subclass>

<class name="BaseEntity" abstract="true">
</class>

but i feel, with this u can only achieve 1 level of inheritance..

Mrityunjay
+1  A: 

How to design database structure in this case considering all the tables have id and version fields (all tables should at least have these two fields).

If you want all tables to have id and version fields, you'll have to use the table per concrete class strategy. See 9.1.5. Table per concrete class or 2.2.4. Mapping inheritance if you are using annotations.

Pascal Thivent