-->
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 and generated SQL
PostPosted: Fri Oct 29, 2010 12:01 pm 
Newbie

Joined: Tue Oct 26, 2010 11:20 am
Posts: 1
Hi

I am writing a HQL, in which I have the following requirement.

Say there are two tables Student and Department.

in which crseDept, crseLevel and crseOption attributes values should be equal.

crseOption can have null values.

HQL:

from Student stu, Department dept where
stu.course = dept.course

generates the following SQL.

select * from Student stu, Department dept where
stu.Dept_ID = dept.Dept_ID
and stu.crse_level = dept.crse_level
and stu.crse_option = dept.crse_option

Since the crse_level can be be null. I want the SQL to be generated as

select * from Student stu, Department dept where
stu.Dept_ID = dept.Dept_ID
and nvl(stu.crse_level,'X') = nvl(dept.crse_level,'X')
and stu.crse_option = dept.crse_option

How should I tell in HQL, that this particular field should be compared with nvl function?

Thanks
Sedhu


Top
 Profile  
 
 Post subject: Re: HQL and generated SQL
PostPosted: Sat Oct 30, 2010 1:48 am 
Beginner
Beginner

Joined: Tue Oct 26, 2010 6:12 pm
Posts: 29
Quote:
How should I tell in HQL, that this particular field should be compared with nvl function?


Use the coalesce function which should help you achieve the same result.
http://docs.jboss.org/hibernate/core/3. ... xpressions

Coalesce, IIRC, returns the first non-null value from an expression list or in other words nvl is coalesce with only two parameters.


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.