-->
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.  [ 1 post ] 
Author Message
 Post subject: Equivalent HQL Query for this SQL Update Query ????
PostPosted: Mon Sep 29, 2014 12:09 pm 
Newbie

Joined: Mon Apr 24, 2006 9:14 am
Posts: 5
Hi,

Below SQL is working perfectly....

String sqlString = "UPDATE employee SET employee_status = EXISTS (SELECT employee_status "
+ "FROM company WHERE employee_id=" + employeeId + " AND employee_status = TRUE) where "
+ "employee_id= " + employeeId;
Query query = currentSession().createSQLQuery(sqlString);

When i converted the above SQL query to below HQL query

Query query = currentSession()
.createQuery(
"UPDATE Employee SET employeeStatus = EXISTS (SELECT employeeStatus "
+ "FROM Company WHERE employeeId =:employeeId AND employeeStatus = :employeeStatus) where "
+ "employeeId = :employeeId");
query.setParameter("employeeStatus", true);
query.setParameter("employeeId", employeeId);

Getting the following exception

<AST>:1:79: unexpected AST node: EXISTS
<AST>:1:79: unexpected AST node: EXISTS
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.newValue(HqlSqlBaseWalker.java:1227)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.assignment(HqlSqlBaseWalker.java:1033)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.setClause(HqlSqlBaseWalker.java:747)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.updateStatement(HqlSqlBaseWalker.java:367)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:255)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:249)

could someone help me with the correct HQL query ??? Please let me know my mistakes in the HQL Query.

Thanks.


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

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.