I am faced with very strange problem, and can’t find a way to resolve it. I wrote the following HQL in intellij’s HQL Console
update NewsEntity ne set ne.main=false where ne.main=true
StackTrace
java.lang.IllegalArgumentException: node to traverse cannot be null!
at org.hibernate.hql.ast.util.NodeTraverser.traverseDepthFirst(NodeTraverser.java:31)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:254)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
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)
in RemoteSessionImpl.createQuery(RemoteSessionImpl.java:50)
in RemoteUtil.executeWithClassLoader(RemoteUtil.java:122)
in RemoteUtil$2$1.invoke(RemoteUtil.java:81)
in HibernateEngine.createQuery(HibernateEngine.java:142)
When I write a delete query I don’t have the same problem.
I have based this query around the following article HQL update query. But, can’t seem to figure out why I am still having this problem.
The idea of an ORM like
Hibernateis to avoid such update queries.You’ve just to load the object from the db, change the field and then
Hibernatewill update the object for out.If there’re more objects:
Hibernate also supports DML statements, so to do an
updatequery you should do: