Hibernate:参数索引无效

时间:2012-07-02 09:54:41

标签: java database hibernate

我正在尝试使用hibernate更新我的数据库表但是当我尝试这样做时,我收到以下错误:

10:46:01,034 DEBUG LongType:80 - binding '19991' to parameter: 57
10:46:01,034  INFO LongType:91 - could not bind value '19991' to parameter: 57; Invalid parameter index 57.
10:46:01,049  WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 07009
10:46:01,049 ERROR JDBCExceptionReporter:72 - Invalid parameter index 57.
10:46:01,049 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session

它试图插入19991的这个值已经存在于数据库中,所以我希望它覆盖那里的值,这是完整的错误

org.hibernate.exception.SQLGrammarException: could not update: [com.project.class.dataobject.PSDBusinessAssociate#18962]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2360)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2242)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2542)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
at com.project.class.service.dwr.BusinessAssociateFormService$$EnhancerByCGLIB$$ff37dc8d.updateBusinessAssociate(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:740)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:744)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:593)
at org.directwebremoting.dwrp.BaseCallHandler.handle(BaseCallHandler.java:90)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:120)
at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:141)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265)
at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:124)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:212)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:818)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:624)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: Invalid parameter index 57.
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.getParameter(JtdsPreparedStatement.java:255)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setParameter(JtdsPreparedStatement.java:326)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setLong(JtdsPreparedStatement.java:509)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setLong(NewProxyPreparedStatement.java:703)
at org.hibernate.type.LongType.set(LongType.java:42)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:78)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1932)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2306)
... 57 more

这就是我将文档映射到数据库列的方式

@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@ForeignKey(name = "fk_BusinessAssociate_Document_fitAndProperQuestionnaireId")
@JoinColumn(name = "fitAndProperQuestionnaireId")
@PropertyPresentation(type="documentuploadfield")
private Document fitAndProperQuestionnaire;

表和列的命名也都正确,所以我看不出有什么问题!如果需要添加更多代码,请询问并添加

修改

查询:

update BusinessAssociate set version=?, modifiedBy=?, address1=?, streetTypeId=?, address2=?, address3=?, city=?, stateCode=?, state=?, postCode=?, countryId=?, provinceId=?, islandId=?, percentOwnership=?, comment=?, companyId=?, businessTitleId=?, firstName=?, surname=?, primaryAssociate=?, nationality=?, socialSecurityNumber=?, associateId=?, middleName=?, jobTitle=?, gender=?, previousNames=?, priorAddress1=?, priorStreetTypeId=?, priorAddress2=?, priorAddress3=?, priorCity=?, priorStateCode=?, priorState=?, priorPostCode=?, priorCountryId=?, priorProvinceId=?, priorIslandId=?, workPhoneCountryCode=?, workPhoneCityCode=?, workPhone=?, homePhoneCountryCode=?, homePhoneCityCode=?, homePhone=?, mobilePhoneCountryCode=?, mobilePhoneOperatorCode=?, mobilePhone=?, dateOfBirth=?, cityOfBirth=?, countryOfBirthId=?, proofOfResidentialAddressId=?, addressIdentificationTypeId=?, criminalCheckId=?, fitAndProperQuestionnaireId=? where businessAssociateId=? and version=?

1 个答案:

答案 0 :(得分:0)

嗯,显然有些问题,您应该看到添加更多代码,以便我们可以尝试并提供帮助。
另外,您是否已将hibernate.cfg.xml中的show_sql参数设置为true?
这可以帮助您查看休眠生成的查询,也许(您将不得不计算),您将能够看到正在发生的事情。 不确定如果您的参数数量无效,查询是否存在 - 这是您需要检查的内容。
此外,您可以更改应用程序中的log4j设置,以调试“org.hibernate”下的所有代码。
我认为通过更好的日志记录,您将能够理解您的问题,如果没有 - 应该向我们公开更多代码,以便我们可以提供帮助。