I have a front-end application with a JPA/JAX-RS backend, where i want to make a request to delete a comment on a post.
I'm using the repository pattern, where i have made the following method to delete a comment:
@Override
public Comment delete(Comment comment)
{
return getEntityManager().createQuery("DELETE Comment c WHERE c.id = :id ", Comment.class)
.setParameter("id", comment.getId())
.getSingleResult();
}
here i get the error:
Update/delete queries cannot be typed JPA
Here I'm a bit in doubt of what to do, i could just change the Comment.class and make it a generic query, but inside my facade, which calls the method
I also want to make a conditional check i there was a comment or not
Comment commentToDelete = commentRepository.get(comment);
if(commentToDelete == null){
throw new ResourceNotFoundException(Comment.class, comment);
}
how can i solve this problem in the easiest way, can i return an Object and just cast that, or is there another way to check for the comment and delete it from the database?