错误:
oracle.jbo.DMLConstraintException:
JBO-26048: Constraint "Td_Parent_Id_FK" violated during post operation:
"Insert" using SQL Statement
原因:
When the TdChild row is inserted, the database complains that the value of its Td_Parent_ID foreign key doesn't correspond to any row in the TdParent table.
This occurred because:
The code created the TdChild before the TdParent
TdChild and TdParent entity objects are associated but not composed
The DML operations to save the new entity rows is done in chronological order, so the new TdChild gets inserted before the new TdParent.
解决方法:
public class TdChildImpl extends EntityImpl {
private static EntityDefImpl mDefinitionObject;
@Override
public void postChanges(TransactionEvent e) {
if (getPostState() == STATUS_NEW ||
getPostState() == STATUS_MODIFIED) {
TdParentImpl tdParent= getTdParent();
if (tdParent!= null) {
if (tdParent.getPostState() == STATUS_NEW) {
tdParent.postChanges(e);
}
}
}
super.postChanges(e);
}
}
本文介绍了一种常见的Oracle数据库外键约束错误及其解决方案。当尝试插入子表记录时,若父表尚未创建,则会触发此错误。文章提供了一个具体的Java实现示例,通过调整保存实体对象的顺序来避免该问题。
1313

被折叠的 条评论
为什么被折叠?



