Using the Delete query
Deleting records from a database is a common activity. We can use JPQL to delete individual records or multiple records. JPQL query deals with entities as opposed to database records. In this recipe we will explore the process of deleting entities.
The basic form of the Delete query consists of:
DELETE FROM entity entityIdentificationVariable WHERE condition
For example, to delete the entity whose name is "Donald Baker" we would use the query.
DELETE FROM Patient p WHERE p.firstName = 'Donald' AND p.lastName = 'Baker'
The steps used to create and use a JPQL Delete query include:
- Obtaining an instance of an
- Using the
createQuerymethod to create an instance of a
Querybased on a Delete JPQL string ...