Hibernate Tutorial: Table per Hierarchy Example using xml file

By this inheritance strategy, we can map entire hierarchy of command by single table as it were. Here, an additional column (otherwise called discriminator column) is made in the table to distinguish the class. How about we comprehend the issue first. I need to delineate entire progressive system given underneath into one table of the database. table per class hierarchy of command in inhertance mapping There are three classes in this hierarchy of command. Worker is the super class for Regular_Employee and Contract_Employee classes. We should see the mapping document for this hierarchy of importance.
  1. <?xml version='1.0' encoding='UTF-8'?>  
  2. <!DOCTYPE hibernate-mapping PUBLIC  
  3.           "-//Hibernate/Hibernate Mapping DTD 5.3//EN"  
  4.           "http://hibernate.sourceforge.net/hibernate-mapping-5.3.dtd">  
  6. <hibernate-mapping>  
  7. <class name="com.javacodegeeks.mypackage.Employee" table="emp121" discriminator-value="emp">  
  8. <id name="id">  
  9. <generator class="increment"></generator>  
  10. </id>  
  12. <discriminator column="type" type="string"></discriminator>  
  13. <property name="name"></property>  
  15. <subclass name="com.javacodegeeks.mypackage.Regular_Employee" discriminator-value="reg_emp">  
  16. <property name="salary"></property>  
  17. <property name="bonus"></property>  
  18. </subclass>  
  20. <subclass name="com.javacodegeeks.mypackage.Contract_Employee" discriminator-value="con_emp">  
  21. <property name="pay_per_hour"></property>  
  22. <property name="contract_duration"></property>  
  23. </subclass>  
  25. </class>  
  27. </hibernate-mapping>  
The subclass subelement of class, specifies the subclass. In this case, Regular_Employee and Contract_Employee are the subclasses of Employee class.

javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition