Limit Delete Query With Hibernate
Solution 1:
Other options
You can try to iterate over/load each object and delete it. (seems ugly!!)
OR
You can write two separate HQL queries where the results of the first query are fed into another query (which does the actual delete).
Solution 2:
You can Delete Object "session.delete(object)" The reason is that for deleting an object, Hibernate requires that the object is in persistent state. Thus, Hibernate first fetches the object (SELECT) and then removes it (DELETE). you have to have the object id to remove it
you are using Hibernate because it doesn't depend on the Database that you are using so createQuery is a very strong feature for hibernate , in createQuery first hibernate knew Database type (from jar or your dependency)then Map your SQL statement to the best statement to be run on that Database, in session.createSQLQuery you are writing native SQL so it depend on the DBMS you are using "you lost hibernate feature "
Post a Comment for "Limit Delete Query With Hibernate"