`

Hibernate中You can't operate on a closed ResultSet!!!异常的解决

 
阅读更多
Hibernate.iterate中明明拿到了结果,且hasNext()为true,但next()就是会报错,提示:
You can't operate on a closed ResultSet!!!

抛异常的代码:
((Long) getHibernateTemplate().iterate(query).next()).intValue()


异常信息中提示ResultSet已关闭:
Caused by: org.hibernate.exception.GenericJDBCException: could not get next iterator result
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
    at org.hibernate.impl.IteratorImpl.next(IteratorImpl.java:161)
    at com.yotoo.crm.dao.VisitLogDaoImp.findCountByCriteria(VisitLogDaoImp.java:98)
    at com.yotoo.crm.service.impl.VisitLogServiceImp.findAllVisitLog(VisitLogServiceImp.java:46)
    at com.yotoo.crm.service.impl.VisitLogServiceImp$$FastClassByCGLIB$$4353dcb1.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:55)
    ... 34 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 结果集已关闭。
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:130)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.checkClosed(SQLServerResultSet.java:211)
    at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getLong(SQLServerResultSet.java:2058)
    at org.apache.commons.dbcp.DelegatingResultSet.getLong(DelegatingResultSet.java:278)
    at org.apache.commons.dbcp.DelegatingResultSet.getLong(DelegatingResultSet.java:278)
    at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:61)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:249)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:229)
    at org.hibernate.impl.IteratorImpl.next(IteratorImpl.java:140)
    ... 41 more


问题原因:
调查了半天,还好一位网友的贴子帮我解决了问题,原来Hibernate中如果没有进行事务的配置,resultSet会关闭掉。

解决方法:
在spring的配置文件中添加事务的配置(如果你已经添加,那就不用了),然后在调用出错的Service或DAO中开启事务(添加一个注解:@Transaction)

帮我解决问题的是这个贴子,谢谢这位兄台:
http://my.oschina.net/yotoo/blog/264341
分享到:
评论

相关推荐

    hibernate-shards.jar

    and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these ...

    A program that operate on graph

    "A program that operate on graph" 指的可能是一个专门处理图的软件应用或算法实现。图由节点(或顶点)和边组成,可以用来建模各种问题,如社交网络、交通网络、计算机网络等。下面我们将深入探讨与图相关的知识点...

    Eclipse中Hibernate简单配置和使用

    Eclipse中配置和使用Hibernate框架是Java开发中常见的数据库持久化解决方案。本文将通过详细的步骤介绍Eclipse中配置和使用Hibernate框架,并提供一个简单的示例实现。 Hibernate简介 Hibernate是一个开放源代码的...

    DIY remote camera trigger

    Most SLRs, even entry-level ones, have a remote shutter release socket so you can shoot pictures without actually ...mounted on a tripod, and you operate the camera through the wired remote trigger.

    UE(官方下载)

    You can use these functions to insert a file into the active file, insert a string into the file at every specified increment, sample colors from anywhere on your screen, and more. Using Bookmarks ...

    Why (and How) Networks Should Run Themselves

    anomaly detection algorithms that operate on offline analysis of network traces, operators need classification and detec- tion algorithms that can make real-time, closed-loop deci- sions. Networks ...

    docker on amazon web services

    Docker on Amazon Web Services is for you if you want to build, deploy, and operate applications using the power of containers, Docker, and Amazon Web Services. Basic understanding of containers and ...

    SSD7 选择题。Multiple-Choice

    Which of the following SQL statements can be used to add a row to a table? (a) CREATE (b) INSERT (c) APPEND (d) ADD Correct answer is (b) Your score on this question is: 10.00 ...

    powder toy v90.2

    You can then mine them and watch cool explosions, add intricate wirings, play with little stickmen or operate your machine. You can browse and play thousands of different saves made by the community ...

    camunda-operate-1.0.0.zip

    【camunda-operate-1.0.0.zip】是一个与Zeebe相关的压缩包,它提供了Zeebe的安装和快速入门指南。Zeebe是一个分布式工作流引擎,用于处理大规模的业务流程自动化任务。这个压缩包包含了部署Zeebe所需的所有组件,...

    Motorola GM300无线电台 8 信道改16信道软件及说明(说明为英文版)

    If you can't find it then try your local Motorola dealer who should be able to help at a small cost. You also have to make an interface, or purchase one. To program the radio onto the Amateur band,...

    出国英语实用口语会话实例.docx

    - "Can you check on my room service request?" ### Unit 19: My Laundry Is Not Ready Yet - **情景**: 洗衣服务未完成。 - **常用表达**: - "My laundry is not ready yet." - "When will my clothes be ...

    Universal-USB-Installer

    You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the ...

    Firebird Maestro 17.1 带破解

    You can either grant/revoke permissions for a concrete database object such as table or function, or operate with grantees' privileges in their editors. Firebird server maintenance Firebird server ...

    DeltaV Operate组态工具小技巧

    ### DeltaV Operate组态工具小技巧详解 #### 一、引言 在DeltaV Operate组态工具的使用过程中,经常会遇到一些不被广泛注意但又非常实用的小技巧。这些技巧不仅能提高工作效率,还能避免一些常见的问题。本文将详细...

    [mobi] Building Ethereum DApps: Decentralized Applications on the Ethereum

    You'll begin with a mental model of how Dapps operate, and then dive into designing and implementing smart contracts in Ethereum's Solidity language. You'll explore Ethereum smart contract ...

    TPS63020中文使用手册

    currents can go as high as 3 A while using a single-cell Li-ion or Li-polymer battery, and discharge it down to 2.5 V or lower. The buckboost converter is based on a fixed frequency, pulse width ...

    WizFlow网页编辑

    and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these ...

Global site tag (gtag.js) - Google Analytics