I have the following method in my code.
The above will create a HQL query such as...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


Reply With Quote