Hibernate annoation (Seven inheritance mappings)

Source: Internet
Author: User
Tags inheritance one table

Table per Class strategy:the <union-class> element in Hibernate

Single Table/Class hierarchy strategy:the <subclass> element in Hibernate

Joined subclass Strategy:the <joined-subclass> element in Hibernate

EJB supports three kinds of mapping relationships

1, one table per class (Hibertnate <union-class>)

2, one table for each class level (in Hibernate <subclass>)

3, connected subclasses (corresponding to Join-subclass)

Annotations are not currently supported on interfaces

(1) A table for each class:

Set on the parent class Class-level: @Inheritance (Strategy=inheritancetype.table_per_class)

For example:

Java code

Class A code:
@Entity
@Inheritance (Strategy=inheritancetype.table_per_class)
public class A {
 
private int id;
Private String Aname;
@Id
@GeneratedValue (strategy=generationtype.identity)
public int getId () {
return ID;
}
public void setId (int id) {
This.id = ID;
}
Public String Getaname () {
return aname;
}
public void Setaname (String aname) {
This.aname = Aname;
}
 
}
 
Class B extends a code:
@Entity
public class B extends a{
 
Private String bname;
 
Public String Getbname () {
return bname;
}
 
public void Setbname (String bname) {
This.bname = bname;
}
 
}
Class C extends a code:
@Entity
public class C extends a{
 
Private String CNAME;
 
 
Public String Getcname () {
return CNAME;
}
 
public void Setcname (String cname) {
This.cname = CNAME;
}
 
 
}

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.