Hello,
Im trying to save a simple @OneToMany reference to the database. It saves al the data but it doesn't save the FK's. My code looks like this:
Code:
@Entity
@Table(name = "workweek")
public class WorkWeek extends BaseEntity {
private static final long serialVersionUID = -1601661198784559768L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column(name = "weekNr", nullable = false)
private Integer weekNr;
@ManyToOne
private Person worker;
@OneToMany(mappedBy = "workweek", cascade = CascadeType.ALL)
private List<WorkDay> workdays;
....
@Entity
@Table(name = "workday")
public class WorkDay extends BaseEntity {
private static final long serialVersionUID = 7993536462165923057L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column(name = "date", nullable = false)
private Date date;
@ManyToOne
@JoinColumn(name = "workweek_id")
private WorkWeek workweek;
.....
When I run a test, the db contains a workweek and several workdays but the reference to workweek is null. I generate the MySQL database from the code using hibernate.hbm2ddl.auto. The reference from workweek to worker is saved properly. I can also see in the logging that the week is saved before the workday but the reference to the workweek isnt saved in the workday.
Can anyone tell me what I'm doing wrong?
Thanks in advance!