简体   繁体   中英

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. I was wondering if there is a way to retrieve a list of objects from TraineeStatus model and store it in Trainee model?

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(){

    }

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM