could not extract ResultSet;nested exception is org.hibernate.exception.GenericJDBCException: could

本文讲述了作者在使用Spring Data JPA时遇到`couldnotextractResultSet`错误,经过排查发现缺少@Transactional和@Modifying注解,以及在更新操作中的注意事项,提供了解决这类问题的方法和经验分享。

could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet

今天写一个数据修改后的sql如下:
@Modifying
@Transactional
@Query(value = “UPDATE lt_year_study_flag a set a.book_count = ?1,a.city_count = ?2,a.study_time = ?3,a.class_count = ?4,a.goal_text = ?5 where a.train_code = ?6”,nativeQuery = true)
void updateLYStudyFlag(Integer bookCount, Integer cityCount, Integer studyTime, Integer classCount, String goalText, String trainCode);

一直出现好几个类似这样的错could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet

搞的心态都不好了,查了好几个博主说的都不是我的问题,他们大多数的是自己的数据库字段没有对应上,或者不允许空的字段未传值之类的问题,总之是自己的SQL上的问题,但是我sql检查再三没什么问题。
最后终于排查到了注解,是我没有添加@Transactional 注解和@Modifying 注解。
@Transactional 是声明式事务管理 编程中使用的注解,具体作用请看别人的总结。
@ Modifying 可定义个性化更新操作,例如只涉及某些字段更新时最为常用。

还有一种情况是也是所有检查完之后发现没问题,最后在更新的接收上找到了问题,一般更新的sql直接用void就可以,因为是直接操作数据库。并不需要给后端数据去处理。代码如下:
@Query(value = “UPDATE live_top_bullet a set a.notice_one =?2,a.notice_two =?3,a.notice_thr =?4 where a.live_code =?1”,nativeQuery = true)
viod updateButtleInfo(String liveCode,String noticeOne,String noticeTwo,String noticeThr);

2025-04-01 17:14:59.657 ERROR 6652 --- [nio-5000-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper : Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' 2025-04-01 17:14:59.682 ERROR 6652 --- [nio-5000-exec-5] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [/api] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet] with root cause java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:960) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1019) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-3.4.2.jar:na] at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-3.4.2.jar:na] at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final] at org.hibernate.loader.Loader.getResultSet(Loader.java:2292) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final] at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2050) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final] at or
04-02
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值