查询本机 - 无法提取 ResultSet
Posted
技术标签:
【中文标题】查询本机 - 无法提取 ResultSet【英文标题】:Query Native - could not extract ResultSet 【发布时间】:2019-09-10 19:00:30 【问题描述】:我有一个问题。我解释一下我的情况:SpringBoot + Hibernate + Multitenant (DB master + DB for tenant) + Postgressql。我有两种数据源配置,一种用于主数据库,一种用于每个客户端的数据库。我需要在 JPARepository 中进行本机查询这是我能做到的唯一方法 在我的 JPARepository 中:
public interface IEntity extends JpaRepository<Entity, Integer>
........
@Query(value = "ALTER SEQUENCE entity_identity_seq RESTART", nativeQuery = true)
@Modifying ///Add 1
@Transactional ///Add 2
void restarID();
当我第一次调用该方法时,我得到了:
> Hibernate:
ALTER SEQUENCE entity_identity_seq RESTART
> 2019-09-10 15:41:53.919 WARN 18680 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 02000
> 2019-09-10 15:41:53.919 ERROR 18680 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : La consulta no retornó ningún resultado.
> 2019-09-10 15:41:53.940 ERROR 18680 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet] with root cause
org.postgresql.util.PSQLException: La consulta no retornó ningún resultado.
寻找解决方案后发现需要添加
@Query(value = "ALTER SEQUENCE entity_identity_seq RESTART", nativeQuery = true)
@Modifying
void restarID();
但是在hibernate中没有进行查询,出现了这个错误:
> 2019-09-10 15:46:57.972 ERROR 14392 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query] with root cause
javax.persistence.TransactionRequiredException: Executing an update/delete query
我一直在寻找,发现我应该添加@Transactional
。然后:
@Query(value = "ALTER SEQUENCE entity_identity_seq RESTART", nativeQuery = true)
@Modifying
@Transactional
void restarID();
但是,再回来,我调用方法,我得到了:
> Hibernate:
ALTER SEQUENCE entity_identity_seq RESTART
> 2019-09-10 15:41:53.919 WARN 18680 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 02000
> 2019-09-10 15:41:53.919 ERROR 18680 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : La consulta no retornó ningún resultado.
> 2019-09-10 15:41:53.940 ERROR 18680 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet] with root cause
org.postgresql.util.PSQLException: La consulta no retornó ningún resultado.
请问,有人有什么建议吗? 我是新来的冬眠。谢谢。
【问题讨论】:
您是否尝试将返回类型更改为long
?
不,但现在可以。它失败了。 :(@Selindek
我不知道您的本机查询的返回类型是什么,但根据异常消息,它不是无效的。也许是布尔值?如果您直接从数据库控制台运行该查询,结果是什么?
@Selindek ,我尝试过:布尔值、结果、对象、新对象等。它奏效了。查询返回就好像它是一个插入。
【参考方案1】:
如果有人遇到同样的问题,我已经解决了,在查询旁边添加:
@Modifying(clearAutomatically = true)
@Transactional
【讨论】:
以上是关于查询本机 - 无法提取 ResultSet的主要内容,如果未能解决你的问题,请参考以下文章
针对 SDK Android Q 导致无法完成会话:INSTALL_FAILED_INVALID_APK: 无法提取本机库,res=-2
当安装INSTALL_FAILED_NO_MATCHING_ABIS时出现Android AIR 33错误:无法提取本机库,res = -113