mysql错误: Duplicate entry '2' for key 'stateid'

错误提示为:

javax.servlet.ServletException: org.springframework.dao.DataIntegrityViolationException: could not insert: [com.joyo.vo.Orders]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.joyo.vo.Orders]
 org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
 org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
 org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)


root cause

org.springframework.dao.DataIntegrityViolationException: could not insert: [com.joyo.vo.Orders]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.joyo.vo.Orders]
 org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:624)
 org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
 org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
 org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
 org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690)
 com.joyo.dao.BaseDao.saveObject(BaseDao.java:24)
 com.joyo.dao.impl.OrdersDaoImpl.saveOrder(OrdersDaoImpl.java:116)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 java.lang.reflect.Method.invoke(Unknown Source)
 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
 org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
 org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
 $Proxy10.saveOrder(Unknown Source)
 com.joyo.struts.actions.CartManagerAction.saveorder(CartManagerAction.java:177)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 java.lang.reflect.Method.invoke(Unknown Source)
 org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
 org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
 org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
 org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
 org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)


root cause

org.hibernate.exception.ConstraintViolationException: could not insert: [com.joyo.vo.Orders]
 org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
 org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
 org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
 org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
 org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
 org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
 org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
 org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
 org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
 org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
 org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
 org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
 org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
 org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
 org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
 org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
 org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
 org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
 org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:693)
 org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
 org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
 org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690)
 com.joyo.dao.BaseDao.saveObject(BaseDao.java:24)
 com.joyo.dao.impl.OrdersDaoImpl.saveOrder(OrdersDaoImpl.java:116)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 java.lang.reflect.Method.invoke(Unknown Source)
 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
 org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
 org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
 $Proxy10.saveOrder(Unknown Source)
 com.joyo.struts.actions.CartManagerAction.saveorder(CartManagerAction.java:177)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 java.lang.reflect.Method.invoke(Unknown Source)
 org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
 org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
 org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
 org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
 org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)


root cause

com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '2' for key 'stateid'
 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
 com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
 com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
 com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
 com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
 com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
 com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
 com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
 com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
 org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
 org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
 org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
 org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
 org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
 org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
 org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
 org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
 org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
 org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
 org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
 org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
 org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
 org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
 org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
 org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
 org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
 org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:693)
 org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
 org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
 org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690)
 com.joyo.dao.BaseDao.saveObject(BaseDao.java:24)
 com.joyo.dao.impl.OrdersDaoImpl.saveOrder(OrdersDaoImpl.java:116)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 java.lang.reflect.Method.invoke(Unknown Source)
 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
 org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
 org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
 $Proxy10.saveOrder(Unknown Source)
 com.joyo.struts.actions.CartManagerAction.saveorder(CartManagerAction.java:177)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 java.lang.reflect.Method.invoke(Unknown Source)
 org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
 org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
 org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
 org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
 org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

 

 

解决办法:这是由于在拥有unique限制的字段上添加相同的值造成的,经检查为hibernate中的xx.hbm.xml属性中多对一配置有误,误写为一对一。

你可能感兴趣的:(#,exception)