使用hibernate时出现 TYPE_FORWARD_ONLY 异常,请问什么原因,哪个地方有配置。?(100分)

  • 主题发起人 主题发起人 总有爱
  • 开始时间 开始时间

总有爱

Unregistered / Unconfirmed
GUEST, unregistred user!
异常信息如下:
net.sf.hibernate.JDBCException: Could not execute query
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1546)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.magisky.magiskybean.manager.impl.CommoditPackageManagerImpl.getPa
ckageList(CommoditPackageManagerImpl.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
on(AopUtils.java:282)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
inpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.in
voke(TransactionInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
cAopProxy.java:174)
at $Proxy0.getPackageList(Unknown Source)
at com.magisky.magiskybean.view.action.CommoditPackageAction.execute(Com
moditPackageAction.java:32)
at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
tProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:116
4)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16
0)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:683)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: The result set type is TYPE_FORWARD_ONLY
at net.sourceforge.jtds.jdbc.TdsResultSet.absolute(TdsResultSet.java:519
)
at org.apache.commons.dbcp.DelegatingResultSet.absolute(DelegatingResult
Set.java:205)
at net.sf.hibernate.loader.Loader.advance(Loader.java:629)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:803)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections
(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
... 44 more
哪位遇到过类似的问题。请帮忙一下!
 
不会Java,在网上帮忙找的资料,仅供参考
http://www.gamvan.com/web/jsp/2005/1/197.html
JSP为何抛出TYPE_FORWARD_ONLY异常?
来源: 今晚在线 作者: 我容易么我 类别: 其他 时间: 2005-1-1 TYPE_FORWARD_ONLY游标只能向前!
提问:
JSP运行为什么抛出TYPE_FORWARD_ONLY异常?
回答:

可能你对ResultSet向后滚动的操作.但是你取得Statement 时却使用了缺省是TYPE_FORWARD_ONLY,他只支持向前滚动。
要向后滚动,要设置成TYPE_SCROLL_INSENSITIVE或TYPE_SCROLL_SENSITIVE例如:
Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);

号外:

ResultSet 的Type属性 TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, or TYPE_SCROLL_SENSITIVE是什么意思:
1.TYPE_FORWORD_ONLY,只可向前滚动;
2.TYPE_SCROLL_INSENSITIVE,双向滚动,但不及时更新,就是如果数据库里的数据修改过,并不在ResultSet中反应出来。
3.TYPE_SCROLL_SENSITIVE,双向滚动,并及时跟踪数据库的更新,以便更改ResultSet中的数据。
注意:

笔者一般用PreparedStatement代替Statement,属性也需要设置,设置方法略有不同:
PreparedStatement pps;
sql = "SQL语句";
pps = con.prepareStatement(sql,
ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
 
JSP的 Result set type is TYPE_FORWARD_ONLY 错误
作者: baby 类别: JAVA与C# 发布日期: 2005-01-13 11:07:51 总浏览: 68

ResultSet缺省是TYPE_FORWARD_ONLY,即是向后滚动,要向前滚动,要设置成TYPE_SCROLL_INSENSITIVE或TYPE_SCROLL_SENSITIVE
例如:
Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
 
现在的问题是,我没有创建 Statement 我使用的是hibernate 直接获得 openSession()
然后创建一个Query对象,执行query.list()
这个是在哪里有设置吗?还是其他的lib引起的呢??
 
这是代码
public List getPackageList(String classname, int currentpage, int pagesize) {
if (null == classname)
return null;
String hsql = null;
hsql = "from "
+ classname + "
";
SessionFactory sf = this.getBdao().getSessionFactory();
Session s = null;
List list = null;
try {
s = sf.openSession();
Query query = s.createQuery(hsql);
query.setFirstResult((currentpage - 1) * pagesize);
query.setMaxResults(pagesize);
list = query.list();
} catch (HibernateException e) {
e.printStackTrace();
} finally {
try {
s.close();
sf.close();
} catch (HibernateException e1) {
e1.printStackTrace();
}
}
return list;
}
 
哎,自己解决了!
原来我传入参数的时候pagesize传了个0,所以....
谢谢楼上兄弟的捧场,散分!
 
后退
顶部