[英]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.