Hi there I am new to javax.persistance. The main problem is that I want to delete old (not the last 10000) records in my database (ordered by date desc). I am not able to do a subquery in my sql-statement I would usually expect:
Logging is an object (log) with some information and the occuredAt field is the date (date+time) when it was written to the database
Database:db2 if it is important
SQL:
DELETE FROM Logging WHERE id NOT IN (SELECT id FROM Logging ORDER BY occuredAt DESC LIMIT 10000)
And this is my code I am trying to execute.
EntityManager em = getEntityManager();
String sql = String.format("DELETE FROM %1$s WHERE id NOT IN (SELECT id FROM %1$s ORDER BY occuredAt DESC LIMIT %2$s)",Logging.class.getName(), 10000);
Query qry = em.createQuery(sql);
return qry.executeUpdate();
But this is throwing me an ArgumentException.
Can anybody tell me what I am doing wrong?