我正在编写一个本机查询,并不断获得"无效的utf8mb3字符串:"ACED00"错误这是我的查询
@Query(value = "select " +
"(case when bh.type in :writeOff then 'WRITE_OFF' " +
"when bh.type in :refund then 'RETURN' end) as sector," +
"sum(bh.amount) as size " +
"from `phedon_balance_history` bh " +
"where(bh.type in :writeOff or bh.type in :refund) " +
"and(bh.status = :status) " +
"and ((:startDate is null) or bh.creation_date between :startDate and :endDate) " +
"group by (case when bh.type in :writeOff then 'WRITE_OFF' " +
"when bh.type in :refund then 'RETURN'end)",nativeQuery = true)
List<CommissionProjection> findCommissionStatistic(List<BalanceType> writeOff, List<BalanceType> refund, BalanceTransactionStatus status,
LocalDateTime startDate, LocalDateTime endDate);
我尝试过更改MariaDB版本,也尝试过更改方言中的编码,但没有任何帮助,问题在哪里?
当我尝试使用枚举值作为参数时,遇到了同样的异常。
public List<A> fetchByType(SomeTypeEnum type) {
List<A> query = namedParameterJdbcTemplate.query(
"SELECT * FROM a WHERE some_type = :type",
Map.of("type", type), // SqlException here
this::mapRow
);
return query;
}
简单的解决方案是使用toString
,问题就解决了:
Map.of("type", type.toString())