21.hibernate继承映射table_per_class

t_gen_table表结构:
[img]http://dl.iteye.com/upload/attachment/592697/150fa59d-8349-3522-98e8-d32a38ed1a3f.jpg[/img]
person表结构:
[img]http://dl.iteye.com/upload/attachment/592699/7ce2327d-f8c6-3ecd-b0e6-d42738629ce5.jpg[/img]
teacher表结构:
[img]http://dl.iteye.com/upload/attachment/592701/cc7ffe49-71b3-3a73-a0a1-eae87ba5a995.jpg[/img]
student表结构:
[img]http://dl.iteye.com/upload/attachment/592703/90e4d3a8-aa35-34a0-93ee-8594fe3a9c22.jpg[/img]

package entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.TableGenerator;

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@TableGenerator(
name="t_gen",
table="t_gen_table",//主键生成表名称
pkColumnName="t_pk",//第一个字段名称(主键名称:属性名)
valueColumnName="t_value",//第二个字段名称(保存上次的主键值:属性名)
pkColumnValue="person_pk",//第一个字段值(主键名称值:属性值)
initialValue=1,
allocationSize=1
)
public class Person {

private int id;
private String name;

@Id
@GeneratedValue(generator="t_gen",strategy=GenerationType.TABLE)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}


}




package entity;

import javax.persistence.Entity;

@Entity
public class Teacher extends Person {

private String title;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

}




package entity;

import javax.persistence.Entity;

@Entity
public class Student extends Person {

private int score;

public int getScore() {
return score;
}

public void setScore(int score) {
this.score = score;
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值