Caused by: java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2

来源:互联网 发布:c语言乘法编程 编辑:程序博客网 时间:2024/05/16 15:20
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Parameter index out of range (3 > number of parameters, which is 2).    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377)    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:266)    at com.huiyou.sing.dao.base.impl.BaseDaoImp.findBySqlName(BaseDaoImp.java:165)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)    at java.lang.reflect.Method.invoke(Unknown Source)    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:334)    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:319)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)    at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:91)    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.$Proxy56.findBySqlName(Unknown Source)    at com.huiyou.sing.service.work.impl.MemberMsgServiceImpl.getMemberMsgByFolder(MemberMsgServiceImpl.java:29)    at com.huiyou.sing.service.work.impl.MemberMsgServiceImpl$$FastClassByCGLIB$$9311859.invoke(<generated>)    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)    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.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)    at com.huiyou.sing.service.work.impl.MemberMsgServiceImpl$$EnhancerByCGLIB$$9f3a0281.getMemberMsgByFolder(<generated>)    at test.com.huiyou.service.MemberMsgServiceTest.test(MemberMsgServiceTest.java:27)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)    at java.lang.reflect.Method.invoke(Unknown Source)    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)Caused by: org.hibernate.exception.GenericJDBCException: Parameter index out of range (3 > number of parameters, which is 2).    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)    at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)    at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)    at com.sun.proxy.$Proxy74.setInt(Unknown Source)    at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:57)    at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92)    at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305)    at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300)    at org.hibernate.loader.Loader.bindNamedParameters(Loader.java:1923)    at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1854)    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1728)    at org.hibernate.loader.Loader.doQuery(Loader.java:828)    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)    at org.hibernate.loader.Loader.doList(Loader.java:2438)    at org.hibernate.loader.Loader.doList(Loader.java:2424)    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)    at org.hibernate.loader.Loader.list(Loader.java:2249)    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:331)    at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1784)    at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:229)    at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:156)    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:257)    ... 58 moreCaused by: java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)    at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3717)    at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3701)    at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3743)    at com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:3687)    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setInt(NewProxyPreparedStatement.java:677)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)    at java.lang.reflect.Method.invoke(Unknown Source)    at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)    ... 78 more

出此类异常 说明 sql 写的不规范,例如:

select * from member_msg a where  ( a.deleted=0 or a.deleted is null) order by a.create_time desc

回报这样的错误

原因是

最后“;”是中文的 改成 ;英文分号就通过了

select * from member_msg a where  ( a.deleted=0 or a.deleted is null) order by a.create_time desc;
0 0
原创粉丝点击