Mangnay
Mangnay

Reputation: 1

Spring data jpa , relationship

I have a problem in spring data jpa. I have two tables 1.Reservation 2.Cottage my relationshio is One reservation can have many cottage but i want my foriegn key will be put in reservation. Is that possible? If yes what is the best approach?

Upvotes: 0

Views: 51

Answers (1)

Sivaram Rasathurai
Sivaram Rasathurai

Reputation: 6333

This is one to many relationship. You can represent this cottage in reservation entity as below

.....

 @OneToMany(mappedBy = "cottage", fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    private Set<Cottage> cottage;

....

in the Reservation entity class. For more, please refer the below link

Upvotes: 1

Related Questions