Search code examples
javastored-proceduresjpaconsolidation

How to do regular database cleanup in a JPA application?


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?


Solution

  • You can try Quartz http://www.quartz-scheduler.org/ if you want to stay withing Java boundaries, if it is not a requirement you can go with stored procedures.