|
#1
|
|||
|
|||
|
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));
}
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
Quote:
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 |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |