I keep trying to create a user and delete it afterwards as a part of my tests, but I keep getting the same error org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations even after continuously changing the code in both my Repository and Controller.
This is the code in my Repository:
@Transactional
@Override
public void deleteById(long id) {
Query query = entityManager.createQuery(
"delete from UserModel as u where u.id=:id"
).setParameter("id", id);
query.getSingleResult();
query.executeUpdate();
}
This is the code in my Controller:
@DeleteMapping("/deleteUser")
public @ResponseBody
void deleteUser(@RequestParam long id) {
userRepository.deleteById(id);
ResponseEntity.ok(null);
}