[英]How to retrieve a list of objects from a different table in same model?
我有兩個模型,它們都使用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和值的對象數組,並在我的Trainees模型中使用它。 有可能做到嗎? 謝謝。
試試吧
@Entity
@Table(name="traineeStatus")
public class TraineeStatus {
@OneToMany(mappedBy = "traineestatus")
private List<Trainees> orderItems;
...
// GETTERS and SETTERS
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.