Reputation: 7394
I am getting the following error when I try to implement my query
below:
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token
My query is within a Spring data PersonRepository
that extends CrudRepository
Query:
@Modifying
@Transactional
@Query("DELETE (entity) FROM Person entity WHERE entity.id = :id")
List<Person> deleteFromPersonWithId(@Param("id") String id);
What is the error in my syntax?
Upvotes: 1
Views: 1788
Reputation: 3141
Change your annotations as such;
@Modifying
@Transactional
@Query("DELETE FROM Person WHERE id = :id")
void deleteFromPersonWithId(@Param("id") String id);
Upvotes: 0
Reputation: 567
entityManager.remove(entityInstance)
will remove entity from DB when transaction is committed.
Upvotes: 0
Reputation: 27526
You don't have a right syntax of DELETE query, it should look like this.
DELETE FROM Person entity WHERE entity.id = :id
By the way there is a delete method which does exactly what you want in the CrudRepository
itself. So no need to duplicate it.
Upvotes: 1
Reputation: 69470
Query must be:
@Query("DELETE FROM Person entity WHERE entity.id = :id")
Upvotes: 0