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 9037361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:13:44+00:00 2026-06-16T09:13:44+00:00

I am using HSQLDB for writing junits and my query is like this: String

  • 0

I am using HSQLDB for writing junits and my query is like this:

String queryStr = "from ManualUrlBatchModel where status IN(:status) group by batchUser order by creationTime";
        Query query = getSession(requestType).createQuery(queryStr);
        query.setParameterList("status", status);

I am retrieving one batch per user in the given status (depending on creation time FIFO order).

It runs fine for end to end testing but fails while writing junits.

Exception says:

Caused by: java.sql.SQLException: Not in aggregate function or group by clause: org.hsqldb.Expression@164f8d4 in statement [select manualurlb0_.manual_url_batch_id as manual1_7_, manualurlb0_.creation_time as creation2_7_, manualurlb0_.modification_time as modifica3_7_, manualurlb0_.attribute_list as attribute4_7_, manualurlb0_.batch_name as batch5_7_, manualurlb0_.batch_user as batch6_7_, manualurlb0_.input_s3_key as input7_7_, manualurlb0_.locale as locale7_, manualurlb0_.notify_when_complete as notify9_7_, manualurlb0_.output_s3_key as output10_7_, manualurlb0_.processed_url_count as processed11_7_, manualurlb0_.s3_bucket as s12_7_, manualurlb0_.status as status7_, manualurlb0_.submitted_url_count as submitted14_7_, manualurlb0_.total_url_count as total15_7_ from csi_manual_url_batch manualurlb0_ where manualurlb0_.status in (? , ?) group by manualurlb0_.batch_user order by manualurlb0_.creation_time]
    [junit]     at org.hsqldb.jdbc.Util.throwError(Unknown Source)
    [junit]     at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
    [junit]     at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
    [junit]     at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
    [junit]     at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
    [junit]     at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
    [junit]     at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1573)
    [junit]     at org.hibernate.loader.Loader.doQuery(Loader.java:696)
    [junit]     at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    [junit]     at org.hibernate.loader.Loader.doList(Loader.java:2228)

I found couple of things on net:

  1. GROUP BY doesn’t work in HSQLDB if group by isnot on the basis of string.
  2. GROUP BY doesn’t work the way I have used (select * …. group by COL1).

I am sure people would have faced this issue earlier, what did you guys do then (apart from not writing the junits :))?
Any help would be appreciated.

  • 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-06-16T09:13:45+00:00Added an answer on June 16, 2026 at 9:13 am

    In standard SQL, the group by clause must contain every selected value except the ones which are aggregate functions.

    select a, b, c, d, sum(e) from table group by a -- INVALID
    select a, b, c, d, sum(e) from table group by a, b  -- INVALID
    select a, b, c, d, sum(e) from table group by a, b, c  -- INVALID
    select a, b, c, d, sum(e) from table group by a, b, c, d -- VALID
    

    The query generated by Hibernate is thus invalid, and AFAIK, the only possible way to make a group by HQL query work is to list every scalar column you want to select explicitely (see https://hibernate.onjira.com/browse/HHH-1615):

     select m.foo, m.bar, m.creationTime, m.batchUser  
     from ManualUrlBatchModel m 
     where m.status IN(:status) 
     group by m.foo, m.bar, m.creationTime, m.batchUser 
     order by m.creationTime
    

    If your original query works with MySQL, it’s because MySQL doesn’t respect the SQL standard, and allows queries with group by not listing every selected column. I would suggest not relying on this “feature”, using the same database in tests and in production, and using PostgreSQL instead of MySQL.

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

Sidebar

Related Questions

I am writing a JPA QL named query that would search for documents. This
I am currently using hsqldb for testing and mysql for production. This combination has
I'm trying to initialize a RDF datastore using Jena and HSQLDB . From http://jena.sourceforge.net/DB/hsql-howto.html
I'm using HSQLDB for testing. The database is created from spring by scanning the
I'm new to clojure. Have been playing with jdbc using hsqldb. Did this function
We have a setup where we are using an embedded HSQLDB for backing Hibernate/JPA
I'm using Spring Batch with an HSQLDB in-memory database for Spring Batch metadata. My
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly
Using import datetime in python, is it possible to take a formatted time/date string

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.