Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 29, 2022 12:24 pm GMT

How to execute delete statements with jpa query

Use the executeUpdate method of the Query interface. It will return the number of deleted entries:

public int deleteOldMessages(int daysBack) {  var query = em.createQuery("delete from Message m where createdAt < :givenTimestamp");  query.setParameter(Message.GIVEN_TIMESTAMP, LocalDateTime.now().minusDays(daysBack));  return query.executeUpdate();}

Shared with from Codever. Use copy to mine functionality to add it to your personal snippets collection.


Original Link: https://dev.to/codever/how-to-execute-delete-statements-with-jpa-query-3lp4

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To