1.坑爹的 JpaRepository!
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2023-11-06 18:38:53.129 WARN 14940 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1064, SQLState: 42000
2023-11-06 18:38:53.129 ERROR 14940 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't.call_time >= '2023-10-07 00:00:00.0' and t.call_time <= '2023-11-06 18:38:22.' at line 1
我实在没搞懂,这里的 .0 和 . 是从哪里来的。
于是找了半天,最后发现是 因为SQL那里 没加空格...
用的 JpaRepository
2.BigInteger 不能转成Integer
map 是查数据库得到的,sql大概是这样的:
SELECT product,sum(if(xx_status is not null and xx_status =1,1,0))as push_clue_num, sum(if(xx_status is not null and xx_status =11,1,0))as distribute_success_num ,count(product) as product_clue_num from t_clue where call_time >= :startDateTime group by product
然后我想这里的push_clue_num 肯定就是Integer嘛
int pushClueNum= ((Integer) map.getOrDefault("push_clue_num", 0)).intValue();
结果提示我:
{
"timestamp": "2023-11-06T09:11:05.997+0000",
"status": 500,
"error": "Internal Server Error",
"message": "java.math.BigDecimal cannot be cast to java.math.Integer",
"path": "***/completed-push-clue-board"
}
我实在想不明白,哪里来的BigDecimal,我没有用它啊?
最后debug的时候,发现:
我去,这个类型到底是怎么映射出来的,为啥这么随机。
3.导错了Tuple包
List<xx> xxx = JpaResultUtils.processResult(List<Tuple>,xx.class);
平时常用的转化,现在却怎么也转化不了。于是我干瞪眼,找了半天。
最后发现是导错包了。绝了。
应该导入的是javax.persistence包。