Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6336613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:05:29+00:00 2026-05-24T19:05:29+00:00

derived from this question , is it possible to use HQL or Criteria for

  • 0

derived from this question, is it possible to use HQL or Criteria for the following SQL statement:

SELECT 
   e.type, 
   count(e), 
   count(d), 
   count (case when gender = 'male' then 1 else NULL end) AS NumberOfMaleEmployees
from Department d 
JOIN d.employees e
WHERE e.dead = 'maybe' 
GROUP BY e.type

Although google comes up with a few hits that state HQL supports CASE statements, Hibernate 3.6.6 fails with a

QuerySyntaxException: unexpected token: CASE

when I create the query above on an EntityManager instance.

How much of a bad idea is it, to create another query for every e.type to determine the number of males manually, e.g. for every e.type

SELECT 
   count(e), 
from Department d 
JOIN d.employees e
WHERE e.dead = 'maybe', e.type = ugly

Since there could be quite a few types, this is potentially slow. I’d like the database to do the work for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:05:30+00:00Added an answer on May 24, 2026 at 7:05 pm

    Well, it seems, case statements are supported:

    http://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html

    They just don’t seem to work within count(). An alternative would be using sum(case when… then 1 else 0 end) instead

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class derived from Dictionary. I need this class to simulate a
is it possible to return the sizeof a derived class already from base class/struct?
Possible Duplicate: Learning C++: polymorphism and slicing This is building off a question I
I would like to write a ItemsControl derived custom control. This is partially from
This question has been asked before - How we can use CTE in subquery
This question follows on from the problem posted here when i run explain I
i have a class 'MyTextBox' that derives from the default TextBox in Silverlight. This
I have an AST derived from the ANTLR Parser Generator for Java. What I
F# is derived from OCaml, but what major items are missing or added? Specifically
I have a window (derived from JFrame) and I want to disable the close

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.