Alphalearningschool
        

<<< Prev

Next >>>

Up
Table Per Hierarchy

  1. Table Per Hierarchy - Using this strategy, We can map the whole hierarchy by single table only. For this one extra column is created in the table to identify the class.(known as discriminator column).

Pictorial Representation:

Now Mapping file will be:

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE hibernate-mapping PUBLIC  
          "-//Hibernate/Hibernate Mapping DTD 5.3//EN"  
          "http://hibernate.sourceforge.net/hibernate-mapping-5.3.dtd">  
  
<hibernate-mapping>  
<class name="com.qualde" table="employee" discriminator-value="emp">  
<id name="emp_id">  
<generator class="increment"></generator>  
</id>  
  
<discriminator column="type" type="string"></discriminator>  
<property name="emp_name"></property>  
            
<subclass name="com.quale.permanent_Employee" discriminator-value="per_emp">  
<property name="salary"></property>  
<property name="over_time"></property>  
</subclass>  
            
<subclass name="com.qualde.Temporary_Employee" discriminator-value="temp_emp">  
<property name="pay_per_day"></property>  
<property name="contract_duration"></property>  
</subclass>  
            
</class>  
            
</hibernate-mapping>

 

          Note: In case of table per class hierarchy a discriminator column is added by the                           hibernate framework that specifies the type of the record.

            Now table will look like this: