Project
IntelliJ IDEA
Priority
Normal
Type
Bug
Fix versions
No Fix versions
State
Fixed
Assignee
Peter Gromov
Subsystem
Editor. Error Highlighting
Affected versions
No Affected versions
Fixed in build
108.65  
  • Created by   R Toomey
    2 years ago (02 May 2009 01:47)
  • Updated by   Evgeniy Schepotiev
    21 months ago (27 Apr 2010 16:30)
  • Jira: IDEADEV-36651
    (history, comments)
 
IDEA-48819 Idea HQL editor doesn't understand "case when"
0
Issue is visible to: All Users
  The issue is visible to the selected user group only
I have an Idea project with a Spring facet and a Hibernate facet. There is no JPA facet in the project.

Idea's Persistence QL inspection highlights red any usage of case when ... then ... else ... end as "Can't resolve expression".

h4. Repro

Simple:
Query q = getSession().createQuery("select case when f.bar > 0 then 1 else 0 end from Foo f");


More complicated (inside another expression):
Query q = getSession().createQuery("select sum(case when f.bar > 0 then 1 else 0 end) from Foo f group by f.baz desc");


h4. Workaround

The only workaround I could find was to disable Persistence QL inspection on the entire statement:
//noinspection JpaQlInspection
Query q = getSession().createQuery("select case when f.bar > 0 then 1 else 0 end from Foo f");


Which is sad because I find the persistence QL error inspection to be very helpful 99% of the time.

h4. Notes



Environment: Spring 2.5.6, Hibernate 3.2.6 GA
Idea project has Spring facet and Hibernate facet

Issue was resolved
Comments (2)
 
History
 
Linked Issues (?)
 
R Toomey
  R Toomey
30 May 2009 21:55
2 years ago
OK, this is broken even worse in build #9852.

Now you can't silence the error with //noinspection JpaQlInspection, _plus_ you have to put
//noinspection JpaQueryApiInspection above each parameter. See screenshots.

Please, please, please fix this in 8.1.3. Or at least provide a way to shut up the errors.
R Toomey
  R Toomey
31 May 2009 21:42
2 years ago
Workaround is to extract the offending case when clause to a string:

String s = "sum(case when f.bar > 0 then 1 else 0 end)";
Query q = getSession().createQuery("select "+s+" from Foo f group by f.baz desc");