I have an entityrelation like this:
In the ParentObj class:
@OneToMany(mappedBy = "parentObj", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
private List<ChildObj> list;
In the ChildObj class:
@JoinColumn(name="PARENT_OBJ")
@ManyToOne
private ParentObj parentObj;
When the parent object persisted or removed, the child is persisted/removed as well. BUT when I try to remove all the entities with a CriteriaDelete like:
CriteriaDelete<ParentObj> query = builder.createCriteriaDelete(ParentObj.class);
query.from(ParentObj.class);
em.createQuery(query).executeUpdate();
or a simple query like this:
em.createQuery("DELETE FROM ParentObj po").executeUpdate();
I got a ConstraintViolationException, could somebody explain why this is happening?
I'm using org.hibernate.ejb.HibernatePersistence provider with JTA on a Wildfly server.