teacher表结构:
student表结构:
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.JOINED) public class Person { private int id; private String name; @Id @GeneratedValue 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; } }