hibernate继承关系映射的JPA方式实现 ——JOINED

package entity;

import javax.persistence.*;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)

public class Person {
private int id;
private String name;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

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.DiscriminatorValue;
import javax.persistence.Entity;

@Entity
public class Teacher extends Person{

private String tittle;

public String getTittle() {
    return tittle;
}

public void setTittle(String tittle) {
    this.tittle = tittle;
}

}

package entity;

import javax.persistence.DiscriminatorValue;
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;
}

}

你可能感兴趣的:(hibernate继承关系映射的JPA方式实现 ——JOINED)