I\'m saving twitter tweets in my database with spring JPA Repositories. The date of the tweet is saved as Datetime in the MySQL db. Now I want to delete all tweets that are
SOLVED:
Repository:
@Modifying
@Transactional
@Query("DELETE FROM Tweetpost m WHERE m.createdAt < :date")
int removeOlderThan(@Param("date") java.sql.Date date);
Service:
public void removeOldItems() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -360);
java.sql.Date oneYear = new java.sql.Date(cal.getTimeInMillis());
tweetRepository.removeOlderThan(oneYear);
}