<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping package="com.test.entity"> <class name="Employee" table="test_employee" discriminator-value="0" > <meta attribute="sync-DAO">false</meta> <id name="id" type="string" column="emp_id" > <generator class="assigned"/> </id> <discriminator column="emp_type" type="int"/> <property name="empName" column="emp_name" /> <property name="sex" column="sex" /> <property name="age" column="age" /> <subclass name="Leader" discriminator-value="1" > <join table="test_leader" fetch="select"> <key column="emp_id" foreign-key="id"/> <property name="empName" column="emp_name" /> <property name="sex" column="sex" /> <property name="age" column="age" /> <property name="post" column="post" /> </join> </subclass> <subclass name="Manager" discriminator-value="2" > <join table="test_manager" fetch="select"> <key column="emp_id" foreign-key="id"/> <property name="empName" column="emp_name" /> <property name="sex" column="sex" /> <property name="age" column="age" /> <property name="deptId" column="dept_id" /> </join> </subclass> <subclass name="Staff" discriminator-value="3" > <join table="test_staff" fetch="select"> <key column="emp_id" foreign-key="id"/> <property name="empName" column="emp_name" /> <property name="sex" column="sex" /> <property name="age" column="age" /> <property name="job" column="job" /> </join> </subclass> ...
Relational model (4 separate database tables):
Enterprise employee: Employee(emp_id,emp_name,sex,age,emp_type)
emp_type (1: business leaders, 2: managers, 3: ordinary employees)
Data: emp_id_1, leader 1, male, 45, 1
emp_id_2, management 1, male, 36, 2
emp_id_3, employee 1, male, 22, 3
Business leader: Leader(emp_id,emp_name,sex,age, post )
Data: emp_id_1, leader 1, male, 45, 1
Manager: Manager(emp_id,emp_name,sex,age, dept_id )
Data: emp_id_2, admin 1, male, 36, 2
Ordinary employee: Staff (emp_id,emp_name,sex,age, job )
Data: emp_id_3, employee 1, male, 22, 3
Among them: enterprise employees = enterprise leaders + managers + ordinary employees