在5.7以上的版本实现了对功能依赖的检测,MySql默认启用了only_full_group_by SQL模式:
21-Jan-2019 11:59:54.000 SEVERE [catalina-exec-24] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatherServlet] in context with path [/PayMentSystem] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'examination.s.payDay' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
### The error may exist in file [/usr/tomcat/tomcat8/webapps/PayMentSystem/WEB-INF/classes/com/yc/mapper/ExcelReportModelMapper.xml]
### The error may involve com.yc.mapper.ExcelReportModelMapper.financeClass-Inline
### The error occurred while setting parameters
### SQL: select a.className className,a.editionName editionName,a.studentNum studentNum,a.contractedAmountTotal contractedAmountTotal,b.totalFee totalFee ,a.aId,b.payDay from (select ec.className as className,ec.Id as aId,ec.editionName as editionName,count(e.id) as studentNum ,sum(e.contractedAmount) as contractedAmountTotal,ec.Id as Id from examineeclass ec inner join examinee e on ec.Id =e.classId group by ec.Id) a inner JOIN (select bec.Id as bId,bec.editionName as editionName,sum(s.fee) as totalFee,s.payDay as payDay from examineeclass bec inner join examinee e on bec.Id =e.classId inner join studentfees s on s.id=e.id where s.isIdentified=1 group by bec.Id having bec.Id=? or bec.Id=? or bec.Id=? ) b on a.aId=b.bId
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'examination.s.payDay' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'examination.s.payDay' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'examination.s.payDay' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
在/etc/mysql/my.cnf 中,在文件的最末尾加上
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
这样一句,再重启MySql服务