title: Delete huge number of rows from an EJB Timer
body: <p>I need to delete millions of rows from a table from within an EJB Timer.
  The problem is that the timer has a transaction timeout of 90 seconds, so I should divide the work into bite-size chunks.</p>
  
  <p>Since I don't know how many rows can be deleted in 90 seconds the algorithm should loop and delete a few at a time until the time is almost up.</p>
  
  <p>The problem is:
  How can the number of rows to delete be limited elegantly in JPA?
  The delete is made on all rows having a timestamp earlier than a certain date.</p>
  
  <p>I guess it is possible to find the 1000th oldest row and <code>DELETE WHERE timestamp &lt;= {1000th-oldest-row.timestamp}</code> This, however, is not very elegant and I would have to get to the last row in a 1000 to get the timestamp.</p>
  
  <p>Secondly, the timer should trigger immediately again if the table is not clean after the 90 seconds. This can be easily solved but, again, is not very elegant.</p>