Primary Entity
public class CustomerAgreement implements Serializable {
@OneToMany(mappedBy = "customerAgreement", orphanRemoval = true, fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
private List<CustomerAgreementPeriod> agreementPeriods;
Child Entity:
public class CustomerAgreementPeriod implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "CustomerAgreementPeriodSeq", sequenceName = "CUST_AGT_PERIOD_SEQ")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "CustomerAgreementPeriodSeq")
@Column(name = "ID")
private Long id;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "CUSTID")
private CustomerAgreement customerAgreement;
Main:
em.getTransaction().begin();
em.createQuery("delete from CustomerAgreement").executeUpdate();
em.getTransaction().commit();
Exception:
java.sql.SQLIntegrityConstraintViolationException: ORA-02292: integrity constraint (MASTERDATA.FK_J6TS8CGX06F90LLEMER78LFGG) violated - child record found
- I have found in one of answers that Cascading does not work in delete JPQL..
- To use .remove(entity) does not seems good approach?
- To remove child using native queries and then parent query? (i have 5 childs)
- Someone suggest to not to use cascade all with orphanremoval=true and i have changed to Cascade.Persist but then also same exception
Could anyone suggest how to remove entities in single query including child entities from 4-5 different tables having above given structure.