Delete records from more than 1 year ago
<p>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 older than one year. I saw there is the function <code>CURRENT_TIME</code> and I thought of something like <code>CURRENT_TIME - 360</code>. I know thats not the correct syntax but I have no idea how to do this. Here is what I have:</p>

<pre><code>@Modifying
@Transactional
@Query("DELETE FROM Tweetpost t WHERE t.createdAt &gt; ")
int removeOlderThan();
</code></pre>

<p><strong>EDIT SOLVED:</strong></p>

<p>Repository:</p>

<pre><code>@Modifying
    @Transactional
    @Query("DELETE FROM Tweetpost m WHERE m.createdAt &lt; :date")
    int removeOlderThan(@Param("date") java.sql.Date date);
</code></pre>

<p>Service:</p>

<pre><code>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);


    }
</code></pre>