Results 1 to 4 of 4

Thread: Exception with Spring 1.2.5 and Hibernate 3 during update..

  1. #1
    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

  2. #2
    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.

  3. #3
    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

  4. #4

    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

Similar Threads

  1. Spring 1.2.5 and Hibernate 3
    By oliverchua in forum Data
    Replies: 5
    Last Post: Oct 13th, 2005, 08:30 PM
  2. Replies: 2
    Last Post: Aug 31st, 2005, 12:37 PM
  3. Spring code remarks
    By Alarmnummer in forum Architecture
    Replies: 18
    Last Post: Apr 7th, 2005, 07:17 AM
  4. Update path for Spring to Hibernate 3
    By hgrongstad in forum Container
    Replies: 2
    Last Post: Feb 9th, 2005, 03:28 PM
  5. Replies: 3
    Last Post: Nov 8th, 2004, 07:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •