There is a thing you are forgetting to notice:
When using @OneToMany
annotation, you cannot simply use @JoinColumn
. However, on the other side, I mean @ManyToOne
: you can use @JoinColumn
.
It should be clear to you why this works this way, and not the other way around. (How can an entity keep so many IDs in just one column?)
So you have two options here:
1) Use a specific table to store relation between your One
and Many
entities. Something like this:
@OneToMany(cascade=CascadeType.ALL)
@JoinTable(name = "SCHEDULE_SLOTS_MAPPING", joinColumns = @JoinColumn(name = "SCHEDULE_ID"), inverseJoinColumns = @JoinColumn(name = "SCHEDULE_SLOT_ID"))
private List<ScheduleSlot> scheduleSlots;
2) Use the @JoinColumn
on the Many
side of the relationship: (e.g. your ScheduleSlot
class)
@ManyToOne
@JoinColumn(name="SCHEDULE_ID")
private Schedule schedule;