Hibernate annotation Map Inheritance Relationships

Source: Internet
Author: User

Database tables

Users table (user)

Id Username Password

Customer table, Customer table ID Reference user table ID

Id Phone


Employee table (employee), Worker table ID Reference user table ID

Id Qq

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.