简体   繁体   English

如何从相同模型的不同表中检索对象列表?

[英]How to retrieve a list of objects from a different table in same model?

I have two models, both of them are using hibernate and uses mySQL, they have a ManyToOne relationship, I am using AngularJS to display the view. 我有两个模型,它们都使用hibernate和mySQL,它们具有ManyToOne关系,我正在使用AngularJS显示视图。 I was wondering if there is a way to retrieve a list of objects from TraineeStatus model and store it in Trainee model? 我想知道是否有一种方法可以从TraineeStatus模型中检索对象列表并将其存储在Trainee模型中?

TraineeStatus.java 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 TraineeStatus.java

@Entity
@Table(name="traineeStatus")
public class TraineeStatus {

    @Id
    @GeneratedValue
    private int traineeStatusId;
    private String value;

    public TraineeStatus(){

    }

My goal is to retrieve an array of objects from TraineeStatus with id and value inside the object and the use it in my Trainees model. 我的目标是从TraineeStatus中检索对象内部具有ID和值的对象数组,并在我的Trainees模型中使用它。 Is it possible to do it? 有可能做到吗? Thanks in regards. 谢谢。

Try it 试试吧

@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.

相关问题 如何从 firebase 数据库中检索 model 对象列表 - How to retrieve list of model objects from firebase databse 如何使用@XmlElements将不同的对象放入同一列表? - How to different objects into the same list using @XmlElements? 在Apache Jena中将Json-Ld对象的数组读入模型中。如何从模型中检索单个对象? - Read array of Json-Ld Objects into a Model In Apache Jena.How to retrieve individual objects from Model? 如何从JTable单元格中检索数据,而不是从表格模型中检索数据? - How to retrieve the data from the JTable cell and not the data from the table model? 如何在没有未经检查的分配的情况下从通用接口检索对象列表? - How to retrieve a list of objects from generic interface without unchecked assignment? 如何从 Android 中的 Cloud Firestore 检索自定义对象列表 - How to retrieve a list of custom objects from Cloud Firestore in Android 如何使用实现相同接口的不同对象对列表进行排序? - How can I sort a list with different objects that implement the same interface? 如何缓存返回相同对象列表但基于不同条件的方法? - How to cache methods that return the same list of objects, but based on different conditions? 如何从 ArrayList 获取具有相同对象属性的对象列表 - How to get a list of objects with same objects property from an ArrayList by 从包含不同类对象的列表的每个 object 中检索实例变量的特定值 - Retrieve specific values of instance variable from each object of a list containing Objects of different classes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM