Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

spring - the way to map a list of embeddable

I have an embeddable class that is like this

@Data
@Embeddable
@NoArgsConstructor
@AllArgsConstructor
public class BookingDetail  {
    @OneToOne
    private Player player;

    @Column(name = "booking_status")
    private String bookingStatus;
}

and the second class

@Data
@Entity
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "bookings")
public class Booking  {

   //...Id and other fields

    @ElementCollection
    @CollectionTable(name = "player_booking_details", joinColumns = @JoinColumn(name = "booking_id"))
    private List<BookingDetail> playerBookingDetails;
}

now I want the Player class to contains all booking items, for now, I have his class:

@Data
@Builder(builderMethodName = "toBuild")
@Entity
@NoArgsConstructor
@AllArgsConstructor
public class Player {

   //Id and other fields

    @OneToMany(mappedBy = "?")
    private Set<Booking> bookings;
}

but this doesn't work, I need to know what should be the value of mappedBy, as you can see the bookings field in Player class is a list of an embeddable item, when I run the project without adding mappedBy JPA will create 3 tables, player, player_booking_details and player_bookings, and player_bookings always is empty, I know need to add mappedBy but the problem is with List<BookingDetail>

can somebody guide me to solve this problem and remove the extra created table player_bookings from the domain?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...