I have an issue trying to persist an Entity with a @OneToMany Relatioship and I don't get it solved. (Sorry, I'm not an english native speaker).
These are the Entities:
@Entity
@Table(name = "PARENT")
@lombok.ToString
@lombok.EqualsAndHashCode(callSuper = false, of = { "id" })
public class Parent extends EntityBase<Long> {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PARENT_SEQ")
@SequenceGenerator(name = "PARENT_SEQ", sequenceName = "PARENT_SEQ")
@Column(name = "PARENT_ID")
private Long id;
@OneToMany(targetEntity = Child.class, cascade = CascadeType.ALL)
@JoinColumns({ @JoinColumn(name = "PARENT_ID") })
private List<Child> children;
}
The Child Entity looks like this:
@Entity
@Table(name = "CHILD")
@lombok.ToString
@lombok.EqualsAndHashCode(callSuper = false, of = { "id" })
public class Child extends EntityBase<Long> {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CHILD_SEQ")
@SequenceGenerator(name = "CHILD_SEQ", sequenceName = "CHILD_SEQ")
@Column(name = "CHILD_ID")
private Long id;
}
The Exception I get is:
integrity constraint violation: NOT NULL check constraint; SYS_CT_10153 table: CHILD column: PARENT_ID
Since Cascade is set to all, I though, the chidren would be persisted and that this occures after Parent has been persisted. That way the PARENT_ID already exists and will be set as the foreign key in the children rows.
The tables look like this:
PARENT
PARENT_ID NUMBER(30,0) No
CHILD
CHILD_ID NUMBER(30,0) No
PARENT_ID NUMBER(30,0) No
Has anybody an Idea what I'm possibly doing wrong? Thanks in advance for any help.