Last active
April 5, 2020 16:41
-
-
Save revseev/ecde4739d8b8642169b779b6eb8fdec3 to your computer and use it in GitHub Desktop.
JPQL delete with JOIN query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| @Transactional(propagation= Propagation.MANDATORY) | |
| public void bulkDeleteByUserId(Long id) { | |
| // Write all pending changes to the DB | |
| entityManager.flush(); | |
| // Remove all entities from the persistence context | |
| entityManager.clear(); | |
| entityManager.createQuery("DELETE FROM StudentReviewAnswer x " + | |
| "WHERE x IN (SELECT sra FROM StudentReviewAnswer sra " + | |
| "JOIN StudentReview sr ON sra.studentReview.id = sr.id " + | |
| "WHERE sr.user.id =:id)") | |
| .setParameter("id", id) | |
| .executeUpdate(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment