1

我有两张桌子:预订和机器。所以,我有两个课程:

预订

@javax.persistence.Entity
@Table(name = "reservation")
@NamedQueries({
@NamedQuery(
        name = "getActiveReservationByStatus",
        query = "select reservation from Reservation reservation where reservation.status=:status")  
       })
public class Reservation implements Serializable {
    @javax.persistence.Id
    @Column(name = "reservation_id")
    @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
    private int id;
    @Column(name = "reservation_status")
    private int status = 1;
    @Column(name = "user_id")
    private int userId;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy="reservation")
    private List<Machine> machineResultList;   
    public Reservation() {
    }

    public List<Machine> getMachineResultList() {
          return machineResultList;
    }
    public void setMachineResultList(List<Machine> machineResultList) {
        this.machineResultList = machineResultList;
    }

    //getters, setters...
}

机器

@javax.persistence.Entity
@Table(name = "testmachine")

@NamedQueries({
@NamedQuery(
        name = "getMachineByState",
        query = "select testmachine from TestMachine testmachine where testmachine.reservation.userId =:status") ,
@NamedQuery(
        name = "getMachineNameByReservation",
        query = "select machine from TestMachine machine where machine.reservation.status =:status")
      })

public class TestMachine implements Serializable {
    @javax.persistence.Id
    @Column(name = "machine_id")
    @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
    private int id;

    @ManyToOne(cascade= {CascadeType.REFRESH}, fetch=FetchType.LAZY)
    @JoinColumn(name="reservation_id")
    private Reservation reservation;

    @Column(name = "machine_state")
    private boolean state = false;
    @Column(name = "machine_ip")
    private String machineIP;

    public void setReservationId(Reservation reservation) {
        this.reservation = reservation;
    }

    public String getReservationId() {
        return reservation.getReservationPurpose();
    }

    //getters, setters... 

如果我使用 getActiveReservationByStatus 查询,我可以使用在 Reservation 类中定义的 getter 和 setter 从预订表中获取值。但我无法从 machineResultList 中获取值。

我应该如何修改 getMachineResultList getter 以便能够从该列表中获取信息(来自机器表的信息)?

4

0 回答 0