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

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

错误如下:

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)
   */
  @Override
  public 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)
   */
  @Override
  public 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;
  }


相关文章
|
2月前
|
Java Apache 开发者
解决java.lang.IllegalArgumentException: Invalid uri由无效查询引起的问题
最后,当你修改代码以避免这个异常时,保持代码的整洁和可读性同样重要。注释你的代码,用意图清晰的方法名,并确保逻辑简单明了,这样在未来你或其他开发者需要时可以轻松地维护它。
178 20
|
3月前
|
SQL Java 数据库
解决Java Spring Boot应用中MyBatis-Plus查询问题的策略。
保持技能更新是侦探的重要素质。定期回顾最佳实践和新技术。比如,定期查看MyBatis-Plus的更新和社区的最佳做法,这样才能不断提升查询效率和性能。
141 1
|
6月前
|
运维 Cloud Native Java
postman发起post请求遇到报错:java.io.FileNotFoundException (文件名、目录名或卷标语法不正确。)
遇到bug报错,多猜可能的原因,控制变量反复测试,直至找到问题的关键,然后再思考如何解决或者回避。 博客不应该只有代码和解决方案,重点应该在于给出解决方案的同时分享思维模式,只有思维才能可持续地解决问题,只有思维才是真正值得学习和分享的核心要素。如果这篇博客能给您带来一点帮助,麻烦您点个赞支持一下,还可以收藏起来
|
8月前
|
SQL NoSQL Java
Java使用sql查询mongodb
通过MongoDB Atlas Data Lake或Apache Drill,可以在Java中使用SQL语法查询MongoDB数据。这两种方法都需要适当的配置和依赖库的支持。希望本文提供的示例和说明能够帮助开发者实现这一目标。
254 17
|
9月前
|
Java Maven
java项目中jar启动执行日志报错:no main manifest attribute, in /www/wwwroot/snow-server/z-server.jar-jar打包的大小明显小于正常大小如何解决
在Java项目中,启动jar包时遇到“no main manifest attribute”错误,且打包大小明显偏小。常见原因包括:1) Maven配置中跳过主程序打包;2) 缺少Manifest文件或Main-Class属性。解决方案如下:
2207 8
java项目中jar启动执行日志报错:no main manifest attribute, in /www/wwwroot/snow-server/z-server.jar-jar打包的大小明显小于正常大小如何解决
|
8月前
|
SQL Java 数据库连接
【潜意识Java】MyBatis中的动态SQL灵活、高效的数据库查询以及深度总结
本文详细介绍了MyBatis中的动态SQL功能,涵盖其背景、应用场景及实现方式。
835 6
|
8月前
|
Java Windows
【Azure Function】部署Java Function失败:报错deploy [ERROR] Status code 401和警告 'China North 3' may not be a valid region
1:deploy [ERROR] Status code 401, (empty body). 2: China North 3 may not be a valid region,please refer to https://aka.ms/maven_function_configuration#supported-regions for values. 3:  <azure.functions.maven.plugin.version>1.36.0</azure.functions.maven.plugin.version>
114 11
|
9月前
|
SQL NoSQL Java
Java使用sql查询mongodb
通过使用 MongoDB Connector for BI 和 JDBC,开发者可以在 Java 中使用 SQL 语法查询 MongoDB 数据库。这种方法对于熟悉 SQL 的团队非常有帮助,能够快速实现对 MongoDB 数据的操作。同时,也需要注意到这种方法的性能和功能限制,根据具体应用场景进行选择和优化。
349 9
|
9月前
|
运维 网络安全
解决ssh: connect to host IP port 22: Connection timed out报错(scp传文件指定端口)
通过这些步骤和方法,您可以有效解决“ssh: connect to host IP port 22: Connection timed out”问题,并顺利使用 `scp`命令传输文件。
8941 7
|
9月前
|
网络协议 Ubuntu Linux
解决ssh: connect to host IP port 22: Connection timed out报错(scp传文件指定端口)
解决 `ssh: connect to host IP port 22: Connection timed out` 报错涉及检查 SSH 服务状态、防火墙配置、网络连通性和主机名解析等多个方面。通过逐步排查上述问题,并在 `scp` 命令中正确指定端口,可以有效解决连接超时的问题,确保文件传输的顺利进行。希望本文提供的解决方案能帮助您快速定位并解决该错误。
2160 3

热门文章

最新文章