删除使用spring-security-core类的用户对象时违反完整性约束 [英] integrity constraint violation when deleting user object that uses spring-security-core classes

查看:169
本文介绍了删除使用spring-security-core类的用户对象时违反完整性约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用了spring-security-core插件。
我的用户类扩展了SecUser,没有其他任何事情可以做到与众不同
当试图删除用户时,我得到以下错误:


|错误2012-01-02 19:54:57,277 [http-bio-8080-exec-10]错误util.JDBCExceptionReporter - 参照完整性约束违规:FK6630E2AB3FFA32A:PUBLIC.SEC_USER_SEC_ROLE FOREIGN KEY(SEC_USER_ID)REFERENCES PUBLIC.SEC_USER ID); SQL语句:
从sec_user中删除,其中id =?和版本=? [23003-147]

|错误2012-01-02 19:54:57,294 [http-bio-8080-exec-10] ERROR events.PatchedDefaultFlushEventListener - 无法使数据库状态与会话同步

由JdbcSQLException导致:参照完整性约束冲突:FK6630E2AB3FFA32A:PUBLIC.SEC_USER_SEC_ROLE FOREIGN KEY(SEC_USER_ID)REFERENCES PUBLIC.SEC_USER(ID); SQL语句:
从sec_user中删除,其中id =?和版本=? [23003-147]


任何想法为什么我得到整合约束违规



 集合< SecUserSecRole> userRoles = SecUserSecRole.findAllBySecUser(yourUserObject); 
userRoles * .delete();
user.delete();


I use the spring-security-core plugin in my application. My user class extends SecUser and nothing else is done that could be out of the ordinary When trying to delete a user i get the following error

| Error 2012-01-02 19:54:57,277 ["http-bio-8080"-exec-10] ERROR util.JDBCExceptionReporter - Referential integrity constraint violation: "FK6630E2AB3FFA32A: PUBLIC.SEC_USER_SEC_ROLE FOREIGN KEY(SEC_USER_ID) REFERENCES PUBLIC.SEC_USER(ID)"; SQL statement: delete from sec_user where id=? and version=? [23003-147]
| Error 2012-01-02 19:54:57,294 ["http-bio-8080"-exec-10] ERROR events.PatchedDefaultFlushEventListener - Could not synchronize database state with session

Caused by JdbcSQLException: Referential integrity constraint violation: "FK6630E2AB3FFA32A: PUBLIC.SEC_USER_SEC_ROLE FOREIGN KEY(SEC_USER_ID) REFERENCES PUBLIC.SEC_USER(ID)"; SQL statement: delete from sec_user where id=? and version=? [23003-147]

any idea why i get the integrtiy constraint violations

解决方案

The reason that you are getting the integrity violation exception is because of the fact that spring security creates a junction table SEC_USER_SEC_ROLE between the SEC_USER and SEC_ROLE tables ( a user can have multiple roles and vice-versa). To delete the user object you can use the following code:

    Collection<SecUserSecRole> userRoles = SecUserSecRole.findAllBySecUser(yourUserObject);
    userRoles*.delete();
    user.delete();

这篇关于删除使用spring-security-core类的用户对象时违反完整性约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆