Friday, February 21, 2014

ADF "cannot find or invalidate its owning entity"

When you use CreateInsert operation to declaratively create new rows in both the master and detail views at the same time, you will have the error that the detail entity "cannot find or invalidate its owning entity".

From the description in Developing Fusion Web Applications with Oracle Application Development Framework, when you use the Create or CreateInsert operation to declaratively create a new row, it performs the following lines of code:
// create a new row for the view object
Row newRow = yourViewObject.createRow();
// mark the row as being "initialized", but not yet new
According to the API of the ADF interface Row, when a created row is in STATUS_NEW (by default) state and the method is called to turn the row into STATUS_INITIALIZED, all updateable entities that this row comprises of, de-register themselves from their respective transaction and validation managers. Assocation and ViewLink finders will not find/include these rows.

So, the workaround of the problem is to turn the new row in the master view back into STATUS_NEW state. Perhaps the easiest declarative way is using the CreateWithParams operation, instead of the CreateInsert operation to create the new row in the master view. The CreateWithParams operation will assign attribute values to the new row and turn the row into STATUS_NEW state. For example, you can even call the operation with a parameter that sets an attribute value to EL expression "#{null}".