0
我有一個奇怪的問題,從hasMany關聯刪除很多對象,然後刪除對象本身。RemoveFrom然後刪除()
我有域名類網站和用戶(我沒有 '屬於關聯' 關係):
class User {
}
class Website {
static hasMany = [websiteUsers : User]
}
而且這種方法:
void deleteUserFromWebsite(User user,Website website){
log.debug "-----> deleteUserFromWebsite()"
println website.websiteUsers
website.removeFromWebsiteUsers(user)
println website.websiteUsers
user.delete(flush:true)
log.debug "deleteUserFromWebsite ----->"
}
當我調用此方法一次,一切都很好,但是當我想在一個請求中同時進行羣發操作時(刪除2個或更多用戶)我有休眠錯誤:
deleted object would be re-saved by cascade (remove deleted object from associations)
發生這種情況是因爲hibernate不會將用戶從網站中的關聯中刪除。
從兩個方法記錄呼叫與不同的用戶:
2013-08-19 16:49:56,769 [http-bio-8080-exec-9] DEBUG website.WebsiteService - -----> deleteUserFromWebsite)
[com.**.security.User : 17, com.**.security.User : 3, com.**.security.User : 12, com.**.security.User : 21, com.**.security.User : 16]
[com.**.security.User : 17, com.**.security.User : 3, com.**.security.User : 21, com.**.security.User : 16]
2013-08-19 16:49:56,777 [http-bio-8080-exec-9] DEBUG website.WebsiteService - deleteUserFromWebsite ----->
[com.**.security.User : 17, com.**.security.User : 3, com.**.security.User : 21, com.**.security.User : 16]
2013-08-19 16:49:56,811 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver - ObjectDeletedException occurred when processing request: [POST] /**/**/** - parameters:
users: 12,16
websiteId: mol24o
deleted object would be re-saved by cascade (remove deleted object from associations): [com.**.security.User#16]. Stacktrace follows:
在第一呼叫休眠去除從關聯用戶(用戶ID:12),但在第二時間,ID爲16的用戶未刪除從很多然後當我想刪除對象時,hibernate當然會拋出一個異常。
有什麼辦法讓hibernate刷新他的緩存並更新websiteUsers?
你可以添加代碼,你正在做大規模刪除 – ikumen
這個問題已經解決了嗎? – Gideon