0

How can I make a many-to-one xml mapping from the stayId of RoomOccupancy to the stayId of Stay. Note that StayId is a value object, therefore it does not contain the whole reference to 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;
}

I would be very glad, if someone could help me out.Thank you in Advance!

Whosayin20
  • 81
  • 1
  • 10

1 Answers1

1

If I understood you, then you need make it like this:

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;
}

Or if you need as xml, just add next code to your xml file

<many-to-one name = "stay" column = "stayId" class="Stay " not-null="true"/>
MxWild
  • 3,080
  • 2
  • 14
  • 15