0
在多對一映射哪一列將作爲外鍵:從地址表,該表列用作學生表一對多和ManToOne註釋
public class Student {
private String studentName;
private Address studentAddress;
public Student(String studentName, Address studentAddress) {
this.studentName = studentName;
this.studentAddress = studentAddress;
}
@ManyToOne(cascade = CascadeType.ALL)
public Address getStudentAddress() {
return this.studentAddress;
}
外鍵和地址類:
public class Address {
private long addressId;
private String street;
@Id
@GeneratedValue
@Column(name = "ADDRESS_ID")
public long getAddressId() {
return this.addressId;
}
@Column(name = "ADDRESS_STREET", nullable = false, length = 250)
public String getStreet() {
return this.street;
}
}
在多對一這是由@JoinColumn和@JoinColumn做
@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;
}
難道我錯過了一些的事情,或者這是正確的,我不明白correclty
什麼是你的問題正是主鍵?你爲什麼不測試一切是否正常並詢問你是否有問題? – 2012-03-16 08:20:01
@JB ...謝謝你的回覆.. ..我已經執行它,它工作正常......但我的問題是它是如何工作自動在manyToOne沒有任何註釋類型JoinColumn或JoinTable ..... – 2012-03-16 08:25:04