I am migrating our app from 2.x to 3.2.5 and face problem with delete queries. I am following the migration guide and using session.createQuery(deleteQuery).updateUpdate(), but the createQuery() throws an exception that the query must start with a SELECT or FROM. At the simplest, I am trying to do a delete with no where clause expecting all to be deleted, using something like "delete from Foo", where Foo is the name of a persistent class. I get the below exeption:
Code:
Caused by: org.hibernate.QueryException: query must begin with SELECT or FROM: delete [delete from Foo]
at org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:83)
at org.hibernate.hql.classic.PreprocessingParser.token(PreprocessingParser.java:108)
at org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:28)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:216)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:185)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
I also referred to the documentation at
http://www.hibernate.org/hib_docs/reference/en/html/batch.html#batch-direct and don't see anything wrong with the usage. I searched and didn't find anything useful, so I would appreciate any help.