An Interest In:
Web News this Week
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
August 29, 2022 12:24 pm GMT
Original Link: https://dev.to/codever/how-to-execute-delete-statements-with-jpa-query-3lp4
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:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To