I want to create a new functionality to delete rows from a table programatically with a limit of rows. That could be thousands of elements to be deleted. The database used is Oracle.
The main problem is that HQL does not support something like a limit or rownum for deletes. We only have setMaxResults for select.
The solutions I have thought about are:
- To use a
selectand then, looping over the list removing withdeleteevery single element from the list. - To use
session.createSQLQueryto be able to uselimitin the query.
Point 1: I want to avoid it, as I don't like having to bring the elements to memory to delete them afterwards, as the elements can be any number (for example 1000000), I have no restrictions in terms of numbers of elements. Is there anything I am missing and I could help me for this solution?
Point 2: I don't know what is the performance difference between session.createSQLQuery and session.createQuery, is there any invonvenience using session.createSQLQuery?
limitdoes not make sense. Point 1 is essence of pure evil, there is no need to withdraw data from database, send them over the networks in order to delete them.