我现在已经创建了3个表。学生电话和学生电话
学生.java
@Entity
@Table(name = "STUDENT")
public class Student {
private long studentId;
private Set<Phone> studentPhoneNumbers = new HashSet<Phone>(0);
@Id
@GeneratedValue
@Column(name = "STUDENT_ID")
public long getStudentId() {
return this.studentId;
}
public void setStudentId(long studentId) {
this.studentId = studentId;
}
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "STUDENT_PHONE", joinColumns = { @JoinColumn(name = "STUDENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "PHONE_ID") })
public Set<Phone> getStudentPhoneNumbers() {
return this.studentPhoneNumbers;
}
public void setStudentPhoneNumbers(Set<Phone> studentPhoneNumbers) {
this.studentPhoneNumbers = studentPhoneNumbers;
}
}
电话.java
@Entity
@Table(name = "PHONE")
public class Phone {
private long phoneId;
private String phoneType;
private String phoneNumber;
@Id
@GeneratedValue
@Column(name = "PHONE_ID")
public long getPhoneId() {
return this.phoneId;
}
public void setPhoneId(long phoneId) {
this.phoneId = phoneId;
}
@Column(name = "PHONE_TYPE", nullable = false, length=10)
public String getPhoneType() {
return this.phoneType;
}
public void setPhoneType(String phoneType) {
this.phoneType = phoneType;
}
@Column(name = "PHONE_NUMBER", nullable = false, length=15)
public String getPhoneNumber() {
return this.phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
}
请通读示例代码https://dzone.com/articles/java/hibernate/hibernate-example/hibernate-mapping-one-to-many-using-annotations-1.html?edition=515297
如何审核上述示例中的学生电话表?
暂无答案!
目前还没有任何答案,快来回答吧!