Short background: I have a software that regularly downloads files. The Statistics of these downloads are stored in the database as a DownloadResult entity, which is in turn associated to the entity representing the download job.
Now I want to make sure, that only a fixed number of the n latest downloads are preserved in the database. AFAIK in a classical (non ORM/JPA) database application, this would be done with a stored procedure.
What would be the right way to do this in a JPA driven application?