I have two tables connected by a foreign key with a one to many relation.
In entity A I have the following:
@org.hibernate.annotations.Cascade( {
org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@OneToMany(mappedBy="monitoredFlight", fetch = FetchType.LAZY)
@OnDelete(action=OnDeleteAction.CASCADE)
private List<bTable> BTable = new ArrayList<BTable>();
Now I try to delete from table A with a bulk delete query:
Query query = em.createQuery("delete from A where originDateTime<:date");
and I get the foreign key constraint error. I decided to do the delete with a join just as I would in mysql, so I changed it to:
Query query = em.createQuery("delete from A join BTable where originDateTime<:date");
and I got a syntax error. I have tried several combination with or without join and nothing works; any ideas?
I am using mysql for the database and java for the language.