墨籽迦 2015-06-05 09:14 采纳率: 100%
浏览 6358

SSH项目删除用户时出错Cannot delete or update

struts2:2.3.20

spring:4.1.5

hibernate:4.3.8

用户与订单一对多的关系,数据库中订单表有用户这个外键。在用户映射文件中已设置cascade="delete"

项目启动无错误,在后台管理用户页面删除用户时报如下错误:

16:35:30,957 WARN SqlExceptionHelper:144 - SQL Error: 1451, SQLState: 23000
16:35:30,959 ERROR SqlExceptionHelper:146 - Cannot delete or update a parent row: a foreign key constraint fails (mall.orderitem, CONSTRAINT FK_hth7ctygtqa5ov7kutghwa1ni FOREIGN KEY (uid) REFERENCES orders (oid))
16:35:30,961 INFO AbstractBatchImpl:208 - HHH000010: On release of batch it still contained JDBC statements
16:35:31,165 ERROR DefaultDispatcherErrorHandler:42 - Exception occurred during processing request: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:163)
at org.springframework.orm.hibernate4.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:730)
at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:592)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:521)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
at com.lonini.mall.user.service.UserService$$EnhancerBySpringCGLIB$$3596b2ab.deleteUser()
at com.lonini.mall.user.adminaction.UserAdminAction.delete(UserAdminAction.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
......

Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:129)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:211)

......

Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (mall.orderitem, CONSTRAINT FK_hth7ctygtqa5ov7kutghwa1ni FOREIGN KEY (uid) REFERENCES orders (oid))
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
......

order实体:

order实体
order关系映射:
order关系映射
user实体:
user实体
user关系映射:
user关系映射
删除用户的JSP页面:
删除用户的JSP页面
删除用户的action方法:
删除用户的action方法
删除用户的Service层:
删除用户的Service层
删除用户的Dao层:
删除用户的Dao层
删除用户的struts2配置:
删除用户的struts2配置
删除用户的spring配置(action):
删除用户的spring配置(action)

  • 写回答

7条回答 默认 最新

  • 程序猿小亮 Java领域优质创作者 2015-06-05 12:24
    关注

    配置的一对多的关系配置的不对把:http://blog.csdn.net/jiuqiyuliang/article/details/41015641

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器