우리는 카운트, 날짜, 액션, 디바이스를 포함하는 여러가지 프로퍼티를 가진 최대 절전 모드 Reporting/ReportingID를 가지고있다. Device라는 하이버 네이트 pojo에 매핑 된 장치 속성 (참고 : 별도로 쿼리 할 필요가 없도록 장치를 가져 오려고합니다).Hibernate HQL과 그룹핑으로 페칭
그래서 내가 가지고있는 것은 다음과 같이 보이는 HQL입니다 :
"SELECT sum(report.deviceTotal), sum(report.settledPricePerDownloadExpense), report.id.device, avg(report.settledPricePerDownloadExpense), report.id.dCampaignActionTypeId " +
"FROM Reporting report " +
"WHERE report.id.dCampaignReportDate between :startDate and :endDate " +
"AND report.id.dCampaignActionTypeId in (:actionIds) " +
"AND report.id.dCampaign.dCampaignId in (:campaigns) " +
"GROUP by report.id.dCampaignActionTypeId, report.id.device " +
"ORDER by 1";
나는 그 생각 일 것입니다,하지만 난이 오류를 얻을 :
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Column 'dbo.device.device_id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
은 내가이에서 얻을 것은
인을 장치 테이블의 모든 열을 그룹별로 나열해야합니다.entity_id1
,
entity_id2
등 열이있는 곳
something
는 기업이 SQL에
group by entity_id1, entity_id2 ...
로 번역됩니다이다 HQL에서
group by something
작성
기본적으로 HQL 대신 기준을 사용하여 작업 할 수있게되었지만 팀에서는 모든 사람들이 HQL을 사용하기를 원합니다. 나는 내가 기준을 고수하고 그들이 신음하고 신음하도록 내버려 둘 것이라고 생각한다. – arinte