-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: hibernate delete query must begin with SELECT or FROM?
PostPosted: Mon Dec 03, 2007 7:57 pm 
Newbie

Joined: Wed Oct 18, 2006 5:45 pm
Posts: 2
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 04, 2007 4:11 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi Harid,

Try to change the classic parser to ANTLR based parser.
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>

Look into the below thread..
http://forum.hibernate.org/viewtopic.ph ... ect+delete

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 04, 2007 12:25 pm 
Newbie

Joined: Wed Oct 18, 2006 5:45 pm
Posts: 2
ramnath wrote:
Hi Harid,

Try to change the classic parser to ANTLR based parser.
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>

Look into the below thread..
http://forum.hibernate.org/viewtopic.ph ... ect+delete

Thanks for your helpful answer. I changed the factory class to "classic" a few days back to accommodate existing queries without having to update, and didn't realize that it would come back and bite me. I think I am now forced to update them as I will have to support quite a few delete queries as well.

The documentation says that the ANTLR based parser is not mature yet, and recommends using the classic parser for now. Is there a way to use delete queries while using the classic parser? I am suspecting that I will get into a bigger hole trying to solve all the issues with the existing queries and the ANTLR parser not being backwards compatible.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.