I want to delete (JPA 2.1) all patients
from one Hospital
, but run into a problem:
UPDATE/DELETE criteria queries cannot define joins
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaDelete<PatientEntity> delete = cb.createCriteriaDelete(PatientEntity.class);
Root<PatientEntity> root = delete.from(PatientEntity.class);
Join<PatientEntity, HospitalEntity> join = root.join(PatientEntity_.Hospital);
delete.where(cb.equal(join.get(HospitalEntity_.id), id));
Query query = entityManager.createQuery(delete);
query.executeUpdate();
Error:
UPDATE/DELETE criteria queries cannot define joins
How should I delete all Patients, while the Join cannot be performed?