File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Case .. when statements in HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Case .. when statements in HQL" Watch "Case .. when statements in HQL" New topic

Case .. when statements in HQL

Harsha Pherwani

Joined: Jul 11, 2005
Posts: 27
I have to implement a SQL query (with case when stmt) in HQL.
HQL documentation says that HQL supports the case when statement.
But when i converted the query to HQL, it gives me errors ..

Here is the query:
select prod,
case when length(prod.category) > 0 then prod.category
when length (prod.iTax.icCategoryId) > 0 then
(select pt.portalPcategoryName from Products p join p.iTax ic join ic.pim pim join pim.pT pt where pt.portals.portalId = ortalId and p.productId = prod.productId) end as category
from Products prod where prod.clients.feedId = :feedId and prod.deadUrlLink = :bln1 and = :bln2

The exception i receieve is :
org.hibernate.hql.ast.QuerySyntaxError: unexpected AST node: query

This query works correctly in postgresql.
Can someone point out where I am going wrong.
Thanks a lot.

Harsha Pherwani

Joined: Jul 11, 2005
Posts: 27
Or does anyone know how to use the CaseFragment stmt (which I am assuming is for Case when stmt) using the criteria API ?
I agree. Here's the link:
subject: Case .. when statements in HQL
jQuery in Action, 3rd edition