错误如下:

java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!

at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterDescriptor(ParameterMetadata.java:79)
at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterExpectedType(ParameterMetadata.java:85)
at org.hibernate.impl.AbstractQueryImpl.determineType(AbstractQueryImpl.java:421)
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:393)
at org.dao.impl.EmpDaoImpl.queryInfoByName(EmpDaoImpl.java:118)
at org.service.impl.EmpServiceImpl.queryInfoByName(EmpServiceImpl.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy6.queryInfoByName(Unknown Source)
at org.service.impl.EmpServiceImplTest.testQueryInfoByName(EmpServiceImplTest.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

相关代码如下:

/**(非 Javadoc)* <p>Description(描述):根据员工的姓名查询员工信息 </p>* <p>Title: queryInfoByName</p>* @param name* @return* @see org.dao.IEmpDao#queryInfoByName(java.lang.String)*/@Overridepublic Emp queryInfoByName(String name) {Emp emp = null;String hql = " from Emp where ename = ?";Session session = this.getSession();List<Emp> empList  =  session.createQuery(hql).setParameter(1, name).list();if(empList.size()!=0){emp = empList.get(0);}return emp;}

注意看这里:

setParameter(1, name)

很明显,这个地方的1应该改成0,但是我原来就是0来着,网上有人说要改成1.。。。。。。我以为我记错了?想着反正也是个错,何不试试呢。于是就二了起来试了试,也许之前越界是其他的原因,改到后面居然忘了到底改哪里了,于是乎把1重新改成了0之后终于可以用了。

setParameter(1, name)

正确详细代码如下:

/**(非 Javadoc)* <p>Description(描述):根据员工的姓名查询员工信息 </p>* <p>Title: queryInfoByName</p>* @param name* @return* @see org.dao.IEmpDao#queryInfoByName(java.lang.String)*/@Overridepublic Emp queryInfoByName(String name) {Emp emp = null;String hql = " from Emp where ename = ?";Session session = this.getSession();List<Emp> empList  =  session.createQuery(hql).setParameter(0, name).list();if(empList.size()!=0){emp = empList.get(0);}return emp;}

ssh根据姓名查询的时候报错java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!相关推荐

  1. ssh根据姓名查询的时候报错java.lang.IndexOutOfBoundsException: Remember that

    错误如下: java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based! at org.hibe ...

  2. 踩坑系列—mybatis查询报错java.lang.IndexOutOfBoundsException

    sql单独执行正确,但是mybatis查询报错,部分错误信息如下: org.mybatis.spring.MyBatisSystemException: nested exception is org ...

  3. Tomcat无法启动,报错java.lang.NoClassDefFoundError: or...

    今天使用Tomcat 7 时,发现Tomcat无法启动, 报错java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory 以为 ...

  4. flink SQL报错java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLj

    问题 flink SQL连接hive以及hudi 报错java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkAr ...

  5. DRP问题集结(一)-Tomcat无法启动,报错java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory...

    问题一:  Tomcat无法启动,报错java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory 问题二:[Error]Jav ...

  6. WildFly 报错 java.lang.NoClassDefFoundError

    在eclipse上WildFly部署项目后,启动一直报错java.lang.NoClassDefFoundError,功夫不负有心人,终于解决. 解决方案 查了网上很多资料,有说环境变量配置不对的,有 ...

  7. 首次使用eclipes运行项目报错“Java.lang.ClassNotFoundException”

    首次使用eclipes运行项目报错"Java.lang.ClassNotFoundException" 运行项目时提示: 解决方法: 1.点击菜单-Project-Build Au ...

  8. 解决Tomcat下IntelliJ IDEA报错java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener

    解决Tomcat下IntelliJ IDEA报错java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener   笔者在做代 ...

  9. Spring Boot单元测试报错java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]

    一:运行test类方法时候报错 报错 java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. S ...

最新文章

  1. 元旦是星期天,春节是1.29,也是星期天哦,祝贺大家节日了!
  2. Excel教程(12) - 数学和三角函数
  3. android与mysql的交互,与Android中的外部SQLite数据库进行交互.
  4. python的print怎么输出utf-8的编码_原创反转精度算法:小数的终极编码
  5. Python Tricks(十七)—— enumerate 的实现
  6. 如何制作高效率的数据可视化大屏
  7. *BZOJ2330: [SCOI2011]糖果
  8. Code Review 是一场苦涩但有意思的修行 | 凌云时刻
  9. 蛋白质组学技术与药物作用新靶点研究进展
  10. Mysql 索引存放位置
  11. 世界陶瓷卫浴100强榜单发布!
  12. MTK6577+Android环境变量
  13. vue 身份证格式校验
  14. 服务器3D场景建模(五):体素场景(三)
  15. j2ee课程设计—基于activiti的请休假系统
  16. Java设计模式——工厂模式——模拟Spring
  17. 01-mui框架使用概述
  18. 【汇编作业记录Proteus8+keil5 作业 2】
  19. ubuntu下全角半角切换
  20. 性能测试分析软件汇总–开源、商业全部收集

热门文章

  1. ltv价值 应用_用户终生价值Ltv是什么,在游戏设计中如何考虑?
  2. Redis底层实现--字符串
  3. 邻接表1 - 试在邻接表存储结构上实现图的基本操作 insert_vertex 和 insert_arc-数据结构-图-icoding
  4. cf1555C Coin Rows
  5. [贪心专题]CF549G,CF351E,CF226D,CF1276C,CF1148E,CF798D
  6. 强连通分量:洛谷P3387 模板:缩点
  7. P4199-万径人踪灭【FFT】
  8. 51nod1551-集合交易【hall定理,最大权闭合图,网络流】
  9. ATcoder-Replace Digits【线段树】
  10. P1445-[Violet]樱花【数学】