我使用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: [email protected] 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不HSQLDB如果按IsNot運算串的基礎上開展工作。
- GROUP BY不能按我使用的方式工作(通過COL1選擇* ....組)。
我相信人們早些時候會遇到這個問題,那麼你們是怎麼做的(除了沒有寫出合適的:))? 任何幫助,將不勝感激。
有accually一個問題與此有關。例如,如果'foo'是一個實體,而不是查詢將會使連接並從連接的表中添加新的列。 – szefuf