0

如何进行从 RoomOccupancy 的stayId 到 Stay 的stayId 的多对一 xml 映射。请注意,StayId 是一个值对象,因此它不包含对 Stay 的整个引用。

 public class RoomOccupancy {
// generated hibernate id
private Long id;
private LocalDate startDate;
private LocalDate endDate;
private StayId stayId;
}


public class Stay {
// generated hibernate id
private Long id;
private StayId stayId;
}

如果有人可以帮助我,我会很高兴。在此先感谢您!

4

1 回答 1

1

如果我理解你,那么你需要这样做:

public class RoomOccupancy {
private Long id;
private LocalDate startDate;
private LocalDate endDate;
@ManyToOne(fetch = FetchType.EAGER, targetEntity = Stay .class)
    @JoinColumn(name = "stayId")
    private Stay stay;
}    

public class Stay {
private Long id;
}

或者,如果您需要 xml,只需将下一个代码添加到您的 xml 文件

<many-to-one name = "stay" column = "stayId" class="Stay " not-null="true"/>
于 2021-11-26T08:03:49.743 回答