Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Data Access

Reply
 
Thread Tools Display Modes
  #1  
Old Oct 6th, 2005, 02:29 PM
ElPapa ElPapa is offline
Member
 
Join Date: Aug 2004
Location: Tacoma, WA USA
Posts: 49
Default Exception with Spring 1.2.5 and Hibernate 3 during update..

I have the following method in my code.

Code:
    public void updateConversionFlags (String servername) {
    	String query = "update AsyncData r set r.conversionRequired='TRUE' where r.status='PROCESSING' or r.broadcastStatus='PROCESSING' or r.broadcastStatus='RETRY' ";

    	if (servername!=null && !servername.equals("All")) {
    		query = query+" and r.server='"+servername+"'";
    	}
    	
    	//calls the Hibernate query updating object (see ConversionFlagUpdater)
    	HibernateTemplate ht = getHibernateTemplate();
    	ht.execute(new ConversionFlagUpdater(query));
    }
The above will create a HQL query such as...

update AsyncData r set r.conversionRequired='TRUE' where r.status='PROCESSING' or r.broadcastStatus='PROCESSING' or r.broadcastStatus='RETRY' and r.server='FOOBAR'

I have the following HibernateCallback implementing class..

Code:
class ConversionFlagUpdater implements HibernateCallback{
	String query;
	public ConversionFlagUpdater (String query) {
		this.query = query;
	} 
	public Object doInHibernate(Session session) {
		Query hqlQuery = session.createQuery(this.query);
		hqlQuery.executeUpdate();
		return null;
	}
}

However I'm getting the following exception (just a snippet). Why doesn't this code allow me to do an update?

Code:
Error in update: org.springframework.orm.hibernate3.HibernateQueryException: query must begin with SELECT or FROM: 
update [update AsyncData r set r.conversionRequired='TRUE' where r.status='PROCESSING' or r.broadcastStatus='PROCESSING' or r.broadcastStatus='RETRY' and r.server='FOOBAR']; 
nested exception is org.hibernate.QueryException: query must begin with SELECT or FROM: update [update AsyncData r set r.conversionRequired='TRUE' where r.status='PROCESSING' or r.broadcastStatus='PROCESSING' or r.broadcastStatus='RETRY' and r.server='FOOBAR'] org.hibernate.QueryException: query must begin with SELECT or FROM: update [update AsyncData r set r.conversionRequired='TRUE' where r.status='PROCESSING' or r.broadcastStatus='PROCESSING' or r.broadcastStatus='RETRY' and r.server='FOOBAR'] 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:176) at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:152) at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427) at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884) at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:865) at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:89) at
__________________
ElPapa

The delusion that people care about what I think:
http://www.codethought.com/blog
Reply With Quote
  #2  
Old Oct 6th, 2005, 03:49 PM
dvoytenko dvoytenko is offline
Member
 
Join Date: May 2005
Location: San Francisco
Posts: 61
Default

It doesn't seem like a Spring's problem.
I'm not sure if it could be a cause, but in HQL you can't use table aliases for update/delete.
Reply With Quote
  #3  
Old Oct 6th, 2005, 04:19 PM
ElPapa ElPapa is offline
Member
 
Join Date: Aug 2004
Location: Tacoma, WA USA
Posts: 49
Default

Quote:
Originally Posted by dvoytenko
It doesn't seem like a Spring's problem.
I'm not sure if it could be a cause, but in HQL you can't use table aliases for update/delete.
I know.. you use classes.. and that *is* the class. And you're right, it's not a spring problem as I've since found it's the choice of parser used in the Hibernate configuration for Spring...

It appears setting this in the hibernate properties should fix the problem. I'm testing it now..

Code:
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
__________________
ElPapa

The delusion that people care about what I think:
http://www.codethought.com/blog
Reply With Quote
  #4  
Old Sep 7th, 2006, 01:49 PM
mihai.patrascu mihai.patrascu is offline
Junior Member
 
Join Date: Sep 2006
Posts: 6
Default

I had the same problem only that i had explicitly specified org.hibernate.hql.classic.ClassicQueryTranslatorFa ctory for <prop key="hibernate.query.factory_class">

I did not specify org.hibernate.hql.ast.ASTQueryTranslatorFactory, only removed the property from the xml file and it works.

Great post although, as i googled specifically for "query must begin with SELECT or FROM" and found nothing, only when looking for something else i stumbled upon this. 10x
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Spring 1.2.5 and Hibernate 3 oliverchua Data Access 5 Oct 13th, 2005 09:30 PM
Spring JTA transaction and Hibernate Session close exception lihui_pang Data Access 2 Aug 31st, 2005 01:37 PM
Spring code remarks Alarmnummer Architecture Discussion 18 Apr 7th, 2005 08:17 AM
Update path for Spring to Hibernate 3 hgrongstad Core Container 2 Feb 9th, 2005 04:28 PM
i am tired.I am very disappointed to spring!! wprusty EJB 3 Nov 8th, 2004 08:30 PM


All times are GMT -5. The time now is 10:07 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.