WEB开发网
开发学院软件开发Java hibernate annoation (七 继承映射) 阅读

hibernate annoation (七 继承映射)

 2009-09-18 00:00:00 来源:WEB开发网   
核心提示:Table per Class Strategy: the <union-class> element in Hibernate Single Table per Class Hierarchy Strategy: the <subclass> element in Hibernate Join

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

Single Table per Class Hierarchy Strategy: the <subclass> element in Hibernate

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

ejb支持三种映射关系

1,每个类一张表 (hibertnate里对应<union-class>)

2,每个类层次一张表 (在 hibernate里对应<subclass>)

3,连接的子类(对应join-subclass)

目前不支持在接口上进行注解

(1)每个类一张表:

在父类class-level上设置:@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)

例如:

Java代码   

class A代码: 
@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代码: 
@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代码: 
@Entity 
public class C extends A{ 
 
 private String cname; 
 
 
 public String getCname() { 
 return cname; 
 } 
 
 public void setCname(String cname) { 
 this.cname = cname; 
 } 
 
 
} 

1 2  下一页

Tags:hibernate annoation 继承

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接