错误:
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);
}
}