-->
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.  [ 6 posts ] 
Author Message
 Post subject: HQL Query Update Problem
PostPosted: Thu Mar 30, 2006 5:24 am 
Newbie

Joined: Thu Jan 12, 2006 9:41 am
Posts: 15
Location: France
Hi,
I try to make an update using HQL and I have the following exception :

org.hibernate.hql.ast.QuerySyntaxError: expecting "set", found 'centrale' near line 1, column 53 [update com.steria.varese.model.physique.PhyCentrale centrale set centrale.phyGeh.id = :idGeh where centrale.phySiteProduction.id = :idSiteProduction ]

this is the code:

public final static String QUERY_UPDATE_CENTRALE_WITH_GEH = "update "
+ PhyCentrale.class.getName() + " centrale"
+ " set centrale.phyGeh.id = :idGeh "
+ " where centrale.phySiteProduction.id = :idSiteProduction ";


public void changementGeh(PhyCentrale instance){
getSession().createQuery(QUERY_UPDATE_CENTRALE_WITH_GEH)

.setInteger("idSiteProduction",instance.getPhySiteProduction().getId().intValue())
.setInteger("idGeh",instance.getPhyGeh().getId().intValue())
.executeUpdate();
}


Even if there is an exception, the update is done in the database. But the exception disturbs me!!! Can anybody help me?

Thank you for your assistance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 1:26 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Is it possible that the update is happening from some other piece of code? Perhaps you're also making the changes in a persistent object and then flushing? Because I can't see how your update query can work. Update does not allow an alias: the correct syntax is
Code:
update <classname>
  set <property> = <value> [, <property> = <value> ...]
  where <condition>


Top
 Profile  
 
 Post subject: HQL Update Exception
PostPosted: Wed Apr 05, 2006 5:54 am 
Newbie

Joined: Thu Jan 12, 2006 9:41 am
Posts: 15
Location: France
Some precisions.
I use Hibernate version : 3.0.5
Is there any changes in the syntax of the update HQL in this version?

Thanks for your assistance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 05, 2006 5:24 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Not as far as I'm aware. Try the recommended syntax and see if it helps.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 3:25 am 
Newbie

Joined: Thu Nov 17, 2005 12:59 pm
Posts: 18
I agree with tenwit.

Tim, try to remove aliases


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 11:51 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I am observing some change the way update HQL's are working. With hibernate version 3.1.3 the alias'es on update statement are working.

Code:
String hql = "update MyPersistentPojo myPojo set myPojo.propertyOne = ?, myPojo.propertyTwo = ? where myPojo.primaryKey = ?";

Object[] values = new Object[]{ propertyOneObj, propertyTwoObj, primaryKeyObj };
// these are hibernate Type's
StringType stype = new StringType();
DateType   dtype = new DateType();
LongType   ltype = new LongType();
Type[]  types  = new Type[]{ stype, dtype, ltype };

Query query = session.createQuery( hql );
query.setParameters( values, types );

List results = query.list();


However the same Query with Hibernate version 3.0.3 is not working and getting exception as in original post

org.hibernate.hql.ast.QuerySyntaxError: expecting "set", found 'myPojo'
Solution: Removing the alias in the HQL statment is working pretty fine, though.

Is there any difference regarding this alias'es feature between the two versions?
Is there any tweak to make the 3.0.3 HQL's work similar to 3.1.3 version using alias'es?

If anyone has came across such difference with HQL's could you please help me in getting some information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.