org/hibernate/impl/IteratorImpl+java.util.NoSuchElementException: No more result

问题描述

Struts Problem ReportStruts has detected an unhandled exception:[/color]Messages:No more resultsFile:[color=blue]org/hibernate/impl/IteratorImpl.java[/size]Line number:132Stacktracesjava.util.NoSuchElementException: No more results[size=x-small] org.hibernate.impl.IteratorImpl.next(IteratorImpl.java:132) action.LoginAction.getSpace(LoginAction.java:88) action.LoginAction.execute(LoginAction.java:42) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) java.lang.Thread.run(Thread.java:619) 问题补充:这是getSpace( )函数:public void getSpace() {String sql1 = "from Space where username='"+username+"'";SessionFactory sessionFactory1 = new Configuration().configure().buildSessionFactory();Session session1 = sessionFactory1.openSession();Transaction tx1 = session1.beginTransaction();Query q1 = session1.createQuery(sql1);Space space = (Space)q1.iterate().next();HttpServletRequest request1 = ServletActionContext.getRequest();HttpSession sess1 = request1.getSession();sess1.setAttribute("current_userspace", space);tx1.commit();}怎么还要判断的吗?请问怎样修改呢?

解决方案

虽然不知道里面space变量哪来的,不过如果已经有了,不用重新load 直接用也可以的,另外,你要确定userspace=(Space)session.load(Space.class, space.getSpaceID());里面space.getSpaceID()是存在的而不是nullpublic void updateSpace() { int updateused; int updateunused; updateused = space.getUsedsize()+(int)file.length(); updateunused = space.getUnusedsize()-(int)file.length(); SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); space.setUnusedsize(updateunused); space.setUsedsize(updateused); session.update(space); session.flush(); tx.commit(); session.close(); }
解决方案二:
引用应该们问题呀:username 两张表都是varchar类型,长度为45;你们这个是怎么关联的呢?是用外键么,其实你可以不用username关联的啊,直接用user表里的id当做userspace表里的外键
解决方案三:
应该是米没有查找到关联的对象,两个表关联字段的值不匹配提示说userspace.setUnusedsize(updateunused); 这句有问题
解决方案四:
引用有什么本质的不同吗? 这个这个防止SQL注入吧,如果把username直接拼接上去,可能别人会输入特殊的字符串 比如 aaa' or '1'= '1拼接起来就是from Space where username= 'aaa' or '1'= '1'"from Space where username= :name"则是留一个参数位置给 username,填入的值只能当做是username的值 而不能拼接,hql会自动把 :name 换成q1.setParameter("name", username); 里设置的值
解决方案五:
Space space = (Space)list.get(0);这里最好再加上判断if(list!= null && !list.isEmpty()) { space = (Space)list.get(0);}
解决方案六:
因为可能取出来的是空集,所以要判读吧另外一般查询是不需要transaction没关系的,updat和insert是一定要用transaction的public void getSpace() { String sql1 = "from Space where username= :name"; SessionFactory sessionFactory1 = new Configuration().configure().buildSessionFactory(); Session session1 = sessionFactory1.openSession(); Query q1 = session1.createQuery(sql1); q1.setParameter("name", username);List list = q1.list(); //如果结果有多个Space space = (Space)list.get(0); //如果结果确定是唯一的,直接 Space space=(Space) q1.uniqueResult();HttpServletRequest request1 = ServletActionContext.getRequest(); HttpSession sess1 = request1.getSession(); sess1.setAttribute("current_userspace", space); session1.close();}
解决方案七:
action.LoginAction.getSpace() 里调用IteratorImpl.next()出错了 iterator遍历的时候没有判断还有没有下一个就直接去取数据了
解决方案八:
java.util.NoSuchElementException: No more resultsaction.LoginAction.getSpace()取出的是空值,没有判断直接next()了?

时间: 2024-12-30 19:29:20

org/hibernate/impl/IteratorImpl+java.util.NoSuchElementException: No more result的相关文章

java.util.NoSuchElementException: Vector Enumeration 求大神帮忙,在线急等

问题描述 异常一Exceptioninthread"AWT-EventQueue-0"java.util.NoSuchElementException:VectorEnumerationatjava.util.Vector$1.nextElement(Vector.java:305)atjavax.swing.plaf.basic.BasicTableUI.getPreferredSize(BasicTableUI.java:1684)atjavax.swing.JComponent.

hibernate中java.util.Date类型映射

在Hibernate中对于java.util.Date类型的映射为: java类型 Hibernate类型 Mysql类型 java.util.Date.java.sql.Date date DATE java.util.Date.java.sql.Time time TIME java.util.Date.java.sql.Timestamp timestamp TIMESTAMP 如果使用timestamp作为Date类型映射时,具体代码如下: Java代码 public class Use

hibernate操作java.util.Date和java.sql.Date

  Entity类 public class Student {     public Date birth;     // java.util.Date      ................ }   Action Student s = new Student(); s.setBirth(new Date());    // 这里还是java.util.Date add(s); .........................     那么我们知道,JDBC中存入数据库的应该是java

hibernate映射数据库timestamp为java.util.Date类型 丢失时间

问题描述 数据库为mysqlhibernate3.0连接驱动为3.1.13 数据库中的时间字段类型为timestamp,实体类中属性类型为Date映射如下<property name="reserveDate" type="timestamp">            <column name="reserveDate"  />        </property>或者<property name=&qu

java.util包学习笔记一

笔记 学习java2SDK 1.4.0 java.util里边有几个重要的接口,列在这里作为学习的总结: 1 java.util.Enumeration有两个方法hasMoreElements(),nextElement().使用方法如下://打印向量v的所有元素for(Enumeratin e = v.elements(); e.hasMoreElements();){ System.out.println(e.nextElement().toString());}这里注意要调用nextEle

dwr返回时间报错-Error marshalling java.util.Date: For input string: &amp;amp;quot;2013-09-10%2013%3A09&amp;amp;quot;

问题描述 Error marshalling java.util.Date: For input string: "2013-09-10%2013%3A09" 时间文本框: 通过dwr获取res,向表单传值: res[0] = [{devNo:res[0].devNo,sleepTime:res[0].sleepTime,syncTime:formatDate(res[0].syncTime,'yyyy-mm-dd HH:nn'),safeTime:formatDate(res[0].

绑定日志-maven jetty 环境下的Web项目在使用logback slf4j时,slf4j总是绑定java.util.logging

问题描述 maven jetty 环境下的Web项目在使用logback slf4j时,slf4j总是绑定java.util.logging Logger logger = (Logger) LoggerFactory.getLogger(UserAction.class); logger.info("loginUser:username{},password{}",username,password); java.lang.ClassCastException: org.slf4j.

[Google Guava] 2.3-强大的集合工具类:java.util.Collections中未包含的集合工具

原文链接 译文链接 译者:沈义扬,校对:丁一 尚未完成: Queues, Tables工具类 任何对JDK集合框架有经验的程序员都熟悉和喜欢java.util.Collections包含的工具方法.Guava沿着这些路线提供了更多的工具方法:适用于所有集合的静态方法.这是Guava最流行和成熟的部分之一. 我们用相对直观的方式把工具类与特定集合接口的对应关系归纳如下: 集合接口 属于JDK还是Guava 对应的Guava工具类 Collection JDK Collections2:不要和jav

java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp区别和总结

java.util.Date.java.sql.Date.java.sql.Time.java.sql.Timestamp区别和总结   java.lang.Object  ....|__java.util.Date  ..........|__java.sql.Date/java.sql.Timestamp /java.sql.Time [父类]java.util.Date日期格式为:年月日时分秒  [子类]java.sql.Date日期格式为:年月日[只存储日期数据不存储时间数据]  [子类