-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Got exception while using HQL for ALTER table records.
PostPosted: Wed Dec 05, 2007 6:55 am 
Newbie

Joined: Wed Dec 05, 2007 6:45 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.2 ga

Mapping documents:
Code:
<class name="com.UnifiedPersonRecordUpdate" table="tbl_person_update">
      <id name="updateID" column="id">
         <generator class="native" />
      </id>
      <property name="personId" column="person_id" />
      <property name="p1" column="name_P1" />
         </class>


Code between sessionFactory.openSession() and session.close():

Code:
org.hibernate.Session session;
         session=HibernateUtil.getSession();
         org.hibernate.Transaction tx = session.beginTransaction(); 
   
            String hqlUpdate = "UPDATE UnifiedPersonRecordUpdate person set person.p1 = :newName where person.personId = :PersonID";
            // or [color=red]String hqlUpdate = "update Customer set name = :newName where name = :oldName";[/color]            int updatedEntities = session.createQuery( hqlUpdate )
                    .setString( "newName", p1 )
                    .setLong("personId", personId )
                    .executeUpdate();
            tx.commit();
            session.close();


Full stack trace of any exception that occurs:

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: #{backing_search3.Update}: javax.faces.el.EvaluationException: org.hibernate.QueryException: query must begin with SELECT or FROM: UPDATE [UPDATE com.etelic.UnifiedPersonRecordUpdate person set person.p1 = :newName where person.personId = :PersonID]
javax.faces.webapp.FacesServlet.service(FacesServlet.java:225)
org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)


root cause

javax.faces.FacesException: #{backing_search3.Update}: javax.faces.el.EvaluationException: org.hibernate.QueryException: query must begin with SELECT or FROM: UPDATE [UPDATE com.etelic.UnifiedPersonRecordUpdate person set person.p1 = :newName where person.personId = :PersonID]
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
javax.faces.component.UICommand.broadcast(UICommand.java:332)
org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:180)
org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:158)
org.ajax4jsf.framework.ajax.AjaxViewRoot.processApplication(AjaxViewRoot.java:346)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:95)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:245)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)


root cause

javax.faces.el.EvaluationException: org.hibernate.QueryException: query must begin with SELECT or FROM: UPDATE [UPDATE com.etelic.UnifiedPersonRecordUpdate person set person.p1 = :newName where person.personId = :PersonID]
com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:150)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:92)
javax.faces.component.UICommand.broadcast(UICommand.java:332)
org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:180)
org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:158)
org.ajax4jsf.framework.ajax.AjaxViewRoot.processApplication(AjaxViewRoot.java:346)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:95)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:245)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)


root cause

org.hibernate.QueryException: query must begin with SELECT or FROM: UPDATE [UPDATE com.etelic.UnifiedPersonRecordUpdate person set person.p1 = :newName where person.personId = :PersonID]
org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:83)
org.hibernate.hql.classic.PreprocessingParser.token(PreprocessingParser.java:108)
org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:28)
org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:216)
org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:185)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
com.etelic.dao.PersonAddProfileDAOHibernate.updatePeopleRecords(PersonAddProfileDAOHibernate.java:88)
com.etelic.bo.PersonAddBO.updatePeopleByParameters(PersonAddBO.java:28)
com.etelic.manager.PersonAddManager.UpdatePeopleByParameters(PersonAddManager.java:17)
com.etelic.controller.PersonAddProfileInput.Update(PersonAddProfileInput.java:259)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:146)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:92)
javax.faces.component.UICommand.broadcast(UICommand.java:332)
org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:180)
org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:158)
org.ajax4jsf.framework.ajax.AjaxViewRoot.processApplication(AjaxViewRoot.java:346)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:95)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:245)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.14



Name and version of the database you are using:

MYSQL 5


The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with HQL.

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 8:12 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

Try to use without the alias,

String hqlUpdate = "Update UnifiedPersonRecordUpdate set p1 = :newName where personId = :personId";
int updatedEntities = session.createQuery( hqlUpdate )
.setString( "newName", "YOUR NEW NAME" )
.setLong("personId ", personId ) // your long value here
.executeUpdate();
where p1 and personId are the variables in your class UnifiedPersonRecordUpdate.

Hope this helps:-)

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 2:01 am 
Newbie

Joined: Wed Dec 05, 2007 6:45 am
Posts: 3
Thanks for reply ...!!!

problem resolved ..,using different logic..!!!

Thanks and regards
Praveen Soni


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.