1
我有兩個模型,他們都使用hibernate並使用mySQL,他們有一個ManyToOne關係,我使用AngularJS來顯示視圖。我想知道是否有辦法從TraineeStatus模型中檢索對象列表並將其存儲在Trainee模型中?如何從同一模型中的其他表中檢索對象列表?
TraineeStatus.java
@Entity
public class Trainees {
@Id
@GeneratedValue
private int traineesID;
@ManyToOne
private Technologies technologies;
@ManyToOne
private TraineeStatus traineestatus;
private int customersID;
private String name;
private String surname;
private String phoneDetails;
private String email;
public Trainees(){
}
public Trainees(String name, String surname, String phoneDetails, String email, int id, Technologies technologies, TraineeStatus traineestatus, int customersID) {
super();
this.name = name;
this.surname = surname;
this.email = email;
this.phoneDetails = phoneDetails;
this.technologies = technologies;
this.traineestatus = traineestatus;
this.customersID = customersID;
}
//getters and setters
TraineeStatus.java
@Entity
@Table(name="traineeStatus")
public class TraineeStatus {
@Id
@GeneratedValue
private int traineeStatusId;
private String value;
public TraineeStatus(){
}
我的目標是從TraineeStatus與物體內部的ID和價值,在我的學員模型使用它檢索對象的數組。可以做到嗎?謝謝你的問候。
好主意感謝,只是我需要相反的,我需要檢索TraineeStatuses的名單,我已經實現@ManyToOne(取= FetchType.LAZY) @JoinColumn(name = 「traineestatus」 ) private List traineestatus;但它表示目標實體未定義。 –
Spinxas
2014-10-02 12:26:57
/@ ManyToOne註解不能應用於List字段,如果你有「一對多」關聯使用@OneToMany annnotation – kemenov 2014-10-02 12:32:17
我的邏輯是一個或多個學員只能擁有一個狀態,控制器坐在學員身上模型,所以我可以從traineestatus模型中檢索數據,僅從實習生那裏,我認爲可以在實習生模型中檢索整個表格,而不是爲traineestatus模型創建另一個控制器。 – Spinxas 2014-10-02 12:34:13