Delete duplicate records from Database table

I want to delete duplicate records from database table for which tried to use the following code as suggested here.

int query1 = em.createQuery("WITH CTE AS(SELECT e.plant, e.material " + "RN = ROW_NUMBER()OVER(PARTITION BY e.plant, e.material ORDER BY e.plant, e.material) " + "FROM erp.MaterialBalance e ) " + "DELETE FROM CTE WHERE RN > 1").executeUpdate();
But getting error. Is it supported by CUBA or is there any workable suggestion in CUBA?

Mortoza

Hi Mortoza,

Use EntityManager.createNativeQuery() method or QueryRunner to run native SQL queries.

Thank you Konstantin.