如何將對象添加到關係並保留它?Grails更新參考
,如果我做這樣的事情
registrationInstance.addToActionType(id:id)
我得到一個異常
Unique index or primary key violation: "PRIMARY_KEY_E7 ON PUBLIC.ACTION_TYPE_REGISTRATIONS(ACTION_TYPE_ID, REGISTRATION_ID)"; SQL statement: insert into action_type_registrations (action_type_id, registration_id) values (?, ?) [23001-147]
編輯:
如果我寫
registrationInstance.addToActionType(ActionType.get(id))
我得到了同樣的錯誤,但它仍然存在 - 所以如何我可以擺脫那個錯誤嗎?
EDIT2:
如果我嘗試刪除的對象:
registrationInstance.removeFromActionType(ActionType.get(id))
我receve以下錯誤(有時,不是永諾)
Eindeutiger Index oder Primarschlüssel verletzt: "PRIMARY_KEY_E7 ON PUBLIC.ACTION_TYPE_REGISTRATIONS(ACTION_TYPE_ID, REGISTRATION_ID)" Unique index or primary key violation: "PRIMARY_KEY_E7 ON PUBLIC.ACTION_TYPE_REGISTRATIONS(ACTION_TYPE_ID, REGISTRATION_ID)"; SQL statement: update action_type_registrations set action_type_id=? where registration_id=? and action_type_idx=? [23001-147]
我也試過這個,但是我得到了同樣的錯誤 – 2012-01-13 14:46:38
我使用'ActionType.load(id)'代替;它不會從數據庫中檢索實例,而只是創建一個代理。由於你只設置外鍵,所以比裝載外鍵便宜很多。 – 2012-01-13 15:20:17