如何将对象添加到关系中并保持关系?

如果我做那样的事情

registrationInstance.addToActionType(id:id)

我有一个异常(exception)
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))

我遇到了同样的错误,但仍然存在-那么如何摆脱该错误?

编辑2:

如果我尝试删除一个对象:
registrationInstance.removeFromActionType(ActionType.get(id))

我收到以下错误(有时并非总是如此)
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]

最佳答案

您必须将对象本身添加到关系中:

registrationInstance.addToActionType(ActionType.load(id))
registrationInstance.save()

关于hibernate - Grails更新引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8852193/

10-08 23:21