Table Per Sub Class Hierarchy in Hibernate ORM

Program 1

package beans;

public class Employee 
{
    private int eid;
    private String ename;
    private int esalary;

    public Employee() {
    }

    public int getEid() {
        return eid;
    }

    public void setEid(int eid) {
        this.eid = eid;
    }

    public String getEname() {
        return ename;
    }

    public void setEname(String ename) {
        this.ename = ename;
    }

    public int getEsalary() {
        return esalary;
    }

    public void setEsalary(int esalary) {
        this.esalary = esalary;
    }
    
}

Program 2

package beans;

public class Manager extends Employee
{
   private int hra;
   private int da;

    public Manager() {
    }

    public int getHra() {
        return hra;
    }

    public void setHra(int hra) {
        this.hra = hra;
    }

    public int getDa() {
        return da;
    }

    public void setDa(int da) {
        this.da = da;
    }
   
}

Program 3

package beans;

public class Clerk extends Employee
{
   int ta;

    public Clerk() {
    }

    public int getTa() {
        return ta;
    }

    public void setTa(int ta) {
        this.ta = ta;
    }
   
}

Program 5

<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>  
        <property name="connection.url">jdbc:mysql://localhost/inherit</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root@data</property>
        <property name="connection.pool_size">10</property>
         <property name="hbm2ddl.auto">create</property>
        <property name="show_sql">true</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <mapping resource="resources/Employee.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *