Annotates a repository method to perform delete operations.
The Delete
annotation indicates that the annotated repository method requests one or more
entities to be removed from the database. To request deletion of specific entity instances, the annotated
repository method must have a single parameter whose type must be one of the following:
- The entity to be deleted.
- An
Iterable
of entities to be deleted. - An array of entities to be deleted.
The return type of the annotated method must be void
, boolean
, a numeric primitive type
(such as int
), or a corresponding primitive wrapper type (such as Integer
).
A boolean return type indicates whether or not an entity was deleted from the database.
A numeric return type indicates how many entities were deleted from the database.
Deletion of a given entity is performed by matching the entity's Id. If the entity is versioned (e.g.,
with jakarta.persistence.Version
), the version is also checked for consistency during deletion.
Properties other than the Id and version do not need to match for deletion.
For example, consider an interface representing a garage:
@Repository
interface Garage {@Delete
Car unpark(Car car); }
If this annotation is combined with other operation annotations (e.g., @Insert
, @Update
,
@Save
), it will throw an UnsupportedOperationException
as only one operation type can be specified.
If the unique identifier of an entity is not found in the database or its version does not match, and the return
type of the annotated method is void
or Void
, the method must
raise OptimisticLockingFailureException
.