我正在使用 HSQLDB 编写junits,我的查询是这样的:
String queryStr = "from ManualUrlBatchModel where status IN(:status) group by batchUser order by creationTime";
Query query = getSession(requestType).createQuery(queryStr);
query.setParameterList("status", status);
我在给定状态下为每个用户检索一批(取决于创建时间 FIFO 顺序)。
它在端到端测试中运行良好,但在编写 junit 时失败。
异常说:
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)
我在网上找到了几件事:
- 如果 group by 不是基于字符串,则 GROUP BY 在 HSQLDB 中不起作用。
- GROUP BY 不能按照我使用的方式工作(选择 * .... group by COL1)。
我相信人们会更早遇到这个问题,你们当时做了什么(除了不写 junits :))?任何帮助,将不胜感激。