【发布时间】:2013-08-28 13:00:53
【问题描述】:
我遇到了一些奇怪的问题:
我有一张桌子Constrainable 和一张桌子Attribute。在Attribute 表中,我通过外键约束指定Constrainable 属于哪个Attribute。我在Attribute 表中的该外键约束中添加了CASCADE ON DELETE。
现在,如果我想删除 Attribute,Constrainable 也将被删除。这不应该发生,还是我错了?
我正在使用这种方法:
public void remove(IDBObject obj) throws DBException {
if (manager != null) {
IDBObject o = null;
try {
o = manager.getReference(obj.getClass(), obj.getPrimaryKey());
} catch (EntityNotFoundException e) {
throw new DBException("Entity doesnt exist");
}
manager.getTransaction().begin();
manager.remove(o);
manager.getTransaction().commit();
return;
}
throw new DBException("Manager is closed or null");
}
这种行为的原因可能是什么?
更详细的 DB 概要:
Constrainable-Table:
|身份证|
Attribute-Table:
|身份证 |约束ID |价值 | CASCADE ON DELETE 的定义
【问题讨论】:
标签: java mysql sql eclipselink cascade