-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL : Update with a case in the set clause
PostPosted: Wed Apr 02, 2008 5:32 am 
Newbie

Joined: Thu May 24, 2007 4:13 am
Posts: 4
Location: Lyon (France)
Hibernate version: 3.2.5

Is it possible to write some update query like this?
If it is, can someone correct my try?
QUERY
Code:
update RgGeocodage geo
   set geo.geocodageEtat.clef =
   case when (geo.cl1 is null and geo.cl2 is null) then :getClef702
       else :getClef703
   end
   where geo.geocodageRefe.clef = :greClef


StackTrace
Code:
java.lang.ClassCastException: org.hibernate.hql.ast.tree.ParameterNode
   at org.hibernate.hql.ast.tree.CaseNode.getFirstThenNode(CaseNode.java:21)
   at org.hibernate.hql.ast.tree.CaseNode.getDataType(CaseNode.java:17)
   at org.hibernate.hql.ast.tree.BinaryLogicOperatorNode.extractDataType(BinaryLogicOperatorNode.java:168)
   at org.hibernate.hql.ast.tree.BinaryLogicOperatorNode.initialize(BinaryLogicOperatorNode.java:35)
   at org.hibernate.hql.ast.HqlSqlWalker.prepareLogicOperator(HqlSqlWalker.java:1007)
   at org.hibernate.hql.ast.HqlSqlWalker.evaluateAssignment(HqlSqlWalker.java:917)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.assignment(HqlSqlBaseWalker.java:1024)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.setClause(HqlSqlBaseWalker.java:729)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.updateStatement(HqlSqlBaseWalker.java:349)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:237)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)


Thank you for your attention
Sylvain


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 7:53 am 
Newbie

Joined: Thu May 24, 2007 4:13 am
Posts: 4
Location: Lyon (France)
Surprisingly this query is working just fine
Code:
update RgGeocodage geo
   set geo.geocodageEtat.clef =
   case when (geo.cl1 is null and geo.cl2 is null) then 702
       else 703
   end
   where geo.geocodageRefe.clef = :greClef



I'll use this even if I've to "hard code" some values in the query String.


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