-->
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: EntityManager.createQuery barfs on COUNT(CASE statement
PostPosted: Thu Aug 14, 2008 6:19 pm 
Newbie

Joined: Wed Aug 13, 2008 7:38 pm
Posts: 2
I'm using Hibernate JPA on Postgres 8.2, and EntityManager.createQuery
is not liking a case statement in a select written using JQL. The SQL runs perfectly well in PgAdmin.

The following works just fine:

Code:
" SUM ( CASE WHEN (cs.serveTs BETWEEN :beginTs AND :endTs ) THEN 1 ELSE 0 END )  "


However, while each of the following runs well when translated into SQL, each one throws an exception indicating that Hibernate doesn't like the syntax:

Code:
" COUNT ( DISTINCT   CASE WHEN (cs.serveTs BETWEEN :beginTs AND :endTs ) THEN cs.componentId ELSE NULL END )  "

" COUNT ( DISTINCT   (CASE WHEN (cs.serveTs BETWEEN :beginTs AND :endTs ) THEN cs.componentId ELSE NULL END ) )  "   

" COUNT ( CASE WHEN (cs.serveTs BETWEEN :beginTs AND :endTs ) THEN cs.componentId ELSE NULL END )  "



Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 9:07 pm 
Newbie

Joined: Wed Aug 13, 2008 7:38 pm
Posts: 2
Here's an example of the exception thrown when using COUNT ( DISTINCT CASE WHEN

Code:
101976 [main] ERROR org.hibernate.hql.PARSER - line 1:93: unexpected token: CASE
101977 [main] ERROR org.hibernate.hql.PARSER - line 1:98: unexpected token: WHEN

and here's the exception thrown when the extra parenthesis is added to give
COUNT ( DISTINCT (CASE WHEN

Code:
85587 [main] ERROR org.hibernate.hql.PARSER - line 1:93: unexpected token: (
85588 [main] ERROR org.hibernate.hql.PARSER - line 1:99: unexpected token: WHEN


I just retried this after upgrading to the latest jars for hibernate-commons-annotations.jar, hibernate-annotations.jar, hibernate-entitymanager.jar, hibernate3.jar, and ejb3-persistence.jar. and am having the very same results.

Any ideas? I'd like to do my due diligence on prior related issues before reporting this to the Hibernate project as a bug.


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.