我有下一堂课:
@Entity
@Table(name="A")
public class A{
@Id
@NextId(sequence="A_SEQ")
@Column(name="A_ID")
private long aId;
@OneToMany(mappedBy="a", cascade=CascadeType.ALL, orphanRemoval=true)
private Set<B> bSet;
@OneToMany(mappedBy="a")
private Set<E> eSet;
@OneToMany(mappedBy="a", cascade=CascadeType.ALL, orphanRemoval=true)
private Set<D>dSet;
}
@Entity
@Table(name="B")
public class B{
@Id
@NextId(sequence="B_SEQ")
@Column(name="B_ID")
private long bId;
@ManyToOne
@JoinColumn(name="A_ID")
private A a;
@OneToMany(mappedBy="b", cascade=CascadeType.ALL, orphanRemoval=true)
private Set<C> cSet;
}
@Entity
@Table(name="C")
public class C{
@Id
@NextId(sequence="C_SEQ")
@Column(name="C_ID")
private long cId;
@ManyToOne
@JoinColumn(name="B_ID")
private B b;
@OneToMany(mappedBy="c")
private Set<E> eSet;
}
@Entity
@Table(name="D")
public class D{
@Id
@NextId(sequence="D_SEQ")
@Column(name="D_ID")
private long dId;
@ManyToOne
@JoinColumn(name="A_ID")
private A a;
@OneToMany(mappedBy="d", cascade = CascadeType.ALL, orphanRemoval=true)
private Set<E> eSet;
}
@Entity
@Table(name="E")
public class E{
@Id
@NextId(sequence="E_SEQ")
@Column(name="E_ID")
private long eId;
@ManyToOne
@JoinColumn(name="D_ID")
private D d;
@ManyToOne
@JoinColumn(name="C_ID")
private C c;
@ManyToOne
@JoinColumn(name="A_ID")
private A a;
}
另外,我有所有属性的getter和setter。
我想只保存一个类,所有其他类都需要通过级联保存。 但是当我尝试执行下一行时:
newSess.saveOrUpdate(o);
newSess.flush();
我收到下一个错误: 引起:java.sql.BatchUpdateException:ORA-01400:无法插入NULL(“E”。“C_ID”)
我知道我收到此错误,因为C是暂时的。我认为级联注释有问题。
我如何解决这个问题?感谢。