Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.1.2
Mapping documents:<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="test.RateLockInfoWrapper" table="dbo.DLAS_Output">
<id name="id">
<column name="DLAS_RecID" not-null="true"/>
</id>
<property name="status">
<column name="DLAS_Record_Processed"/>
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():this.sessionFactory.getCurrentSession().createQuery(UPDATE_HQL).setParameter(0,String.valueOf(maxId)).executeUpdate();
Full stack trace of any exception that occurs:org.hibernate.QueryException: query must begin with SELECT or FROM: UPDATE [UPDATE test.RateLockInfoWrapper rateLockInfoWrapper set rateLockInfoWrapper.status='Y' where rateLockInfoWrapper.id <= ?]
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:191)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:167)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:134)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:113)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1602)
at test.RateLockInfoDAO.updateSelectedRateLockInfos(RateLockInfoDAO.java:93)
Name and version of the database you are using:SQL Server
The generated SQL (show_sql=true):N/A
Debug level Hibernate log excerpt:org.hibernate.QueryException: query must begin with SELECT or FROM: UPDATE [UPDATE test.RateLockInfoWrapper rateLockInfoWrapper set rateLockInfoWrapper.status='Y' where rateLockInfoWrapper.id <= ?]
Hi,
I am doing something like this.sessionFactory.getCurrentSession().createQuery(UPDATE_HQL).setParameter(0,String.valueOf(maxId)).executeUpdate(); within my DAO to update rows of a table
The UPDATE_HQL string looks like this:
UPDATE test.RateLockInfoWrapper rateLockInfoWrapper set rateLockInfoWrapper.status='Y' where rateLockInfoWrapper.id <= ?
Hibernate is throwing a QueryException saying 'query must begin with SELECT or FROM: UPDATE'
Could you please let me know why this error is being thrown?
I also tried createSQLQuery instead with SQL statement instead of HQL. But, it seems I cannot call executeUpdate on a SQL statement.
How do I update values of certain columns of a table?
Thanks.