`

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

    游戏开发数据结构

    a program into two main sections: the data and the instructions that operate on the data. These two sections of a program are commonly called the data structures and the algorithms. This book will ...

    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 ...

    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 ...

    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 ...

    Computer Systems A Programmer's Perspective3e

    Thisbook is wrihen from"a progr'dmme""' pefspective,'describing how application programmers can use their knowledge of a system to write better programs.'Of course, learning what a system i§ ...

    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,...

    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 ...

    [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 ...

    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 ...

    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 ...

    Learning SQLite for iOS(PACKT,2016)

    and Phonegap can be used to build a cross-platform modern app which can benefit from all these technologies – all through creating a complete, customizable application skeleton that you can build on ...

    How to Build a Low-Cost, Extended-Range RFID Skimmer

    Despite this very short nominal range, K r and Wool predicted that a rogue device can communicate with an ISO-14443 RFID tag from a distance of 40-50cm, based on modeling and simulations. Moreover, ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    You can declare functions in a way that allows the compiler to expand them inline rather than calling them through the usual function call mechanism. Pros: Inlining a function can generate more ...

    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 ...

    asyncsocket

    * thread on which the new socket and its delegate should operate. If omitted, [NSRunLoop currentRunLoop] is used. **/ - (NSRunLoop *)onSocket:(AsyncSocket *)sock wantsRunLoopForNewSocket:(AsyncSocket...

Global site tag (gtag.js) - Google Analytics