Database tables
Users table (user)
Customer table, Customer table ID Reference user table ID
Employee table (employee), Worker table ID Reference user table ID
Aircraft Watch (Plane), aircraft includes passenger aircraft and fighter jets, passenger aircraft with toilets, fighters armed
Id |
Type |
Speed |
Wc_position |
Weapon_position |
Entity Mappings
Sub-class shared properties id,version@mappedsuperclasspublic abstract class identifiedentity implements serializable {@Id @generatedvalue@getter private long id; @Version @getter private Int version;private void setid (Long id) { this.id = id; }private void setversion (int version) { this.version = version; }}// The ID of the User is defined in the parent class identifiedentity @entitypublic class user extends identifiedentity {@ getter @Setter private String username; @Getter @Setter private String password;} customer,employee is the subclass of user// their ID is both a primary key and a foreign key// Their primary key refers to the primary key @entity@primarykeyjoincolumn (name = "id") of the user table as a foreign key public class customer extends user { @Getter @Setter private string phone;} @Entity @primarykeyjoincolumn (NAME =  " ID ") public class employee extends user { @Getter @Setter  PRIVATE STRING QQ;} plane is the parent class of A370 and J10 @entity@inheritance (strategy=inheritancetype.single_table) @DiscriminatorColumn (name= " Type ", discriminatortype=discriminatortype.string) public class plane extends Identifiedentity{ private string speed;} @Entity @discriminatorvalue ("370") public class a370 extends plane{ Private string wc_position;} @Entity @discriminatorvalue ("738") public class j10 extends plane{ Private string weapon_position;}
Hibernate annotation Map Inheritance Relationships