Tuesday, 22 July 2008

ADF BC: EO/VO create() state + JBO-25030 revisited

Recently I blogged about why you might receive JBO-25030: Failed to find or invalidate owning entity in ADF BC, a follow up to a further description by Steve Muench.

I'd like to blog about another reason you'll receive JBO-25030 and is related to my recent post on ADF BC: EO/VO initial state post create() explained.

In that blog post it details that an EO/VO that is instantiated and attributes are defaulted via declarative default settings or your own programmatic code, the record's status is set to STATUS_NEW, but the ADFm binding layer overrides this with STATUS_INITIALIZED. This status implies the record is not a candidate to be inserted into the database until the user or calling program changes another value in the record or programmatically changes the status of the record to STATUS_NEW.

This behaviour has further implications for EOs involved in Associations, more commonly known as foreign key or master-detail relationships, and Composition Associations in particular.

In the case of a master-detail EO Association that is not marked as a Composition Association, on the programmer creating the master entity which has its values defaulted (status STATUS_INITIALIZED), and creating a child entity which the user then sets some of the attributes manually (status STATUS_NEW), on pressing commit the programmer may be surprised to receive a foreign-key constraint error returned from the database. This occurs because the master EO status STATUS_INITIALIZED marks it not as a candidate to insert into the database, but the user setting the child EOs attributes does mark it as a candidate for the database with status STATUS_NEW. As such at commit time, the ADF BC mid-tier searches the EO cache looking for records with status STATUS_NEW (and STATUS_MODIFIED to be strictly true, but not considered here), discards the parent record because it has the wrong status, but sends the insert DML to the database for the child record, raising the FK error.

In the case of a master-detail EO Composition Association, on the programmer creating the defaulted parent EO, creating the child EO and manually setting values, and finally pressing commit, this time the programmer will hit "JBO-25030: Failed to find or invalidate owning entity". Why? As you know a Composition Association says that a child can't exist without a parent. So in this case the ADF BC mid-tier is enforcing that the child cannot be inserted into the database with a parent whose status is STATUS_INITIALIZED, because the parent is not a candidate for the database. In other words the mid-tier is enforcing a mandatory FK relationship, with unfortunately a some-what obscure error message.

As detailed in my previous post, you can override the default behaviour of the parent VO such that it's defaulted state will mark it as a candidate to insert into the database.

I'd like to thank Steve Muench for his assistance on the issues behind this blog post.

This post along with other posts describing common JDeveloper error messages are indexed on the Oracle Wiki.


IvoryDome said...

It was very helpful to me. I wished to create details when I create Master and I was getting this Exception. The problem was, I was using CreateInsert of ADFm to create Parent and that was setting the Parent status to STATUS_INITIALIZED. So even I was using createAndInitRow and passing the Parent row Id I was getting this Exception. After reading this article I used createInsertWithParameters of ADFm and yippie it worked.

Note: I don't have VL between Parent and Child. I only have composition association between the entities.

Thanks a lot :)


Anonymous said...

Just wanted to thank you for taking the time to do this post as well as the earlier post. I spent about a day trying to figure out why the BC tester didn't return any error but my page did. Your post probably saved me at least another day or more!

Norman Stonewall said...

I was receiving the JBO-25030 error when I simply visited my creation page. I noticed in the error it had failed to define the owning entity, even though the Entity Association appeared to be fine. Eventually I went into my Entity Association and changed the source and destination attributes and hit OK. Just to change the underlying XML. Next I went back into the entity association and changed the source and destination attributes back to the ones I actually wanted, then tested. Everything worked after that. Hope someone finds this helpful. Thanks for the great articles on this error, it really helped me solve my problem.

Daniel said...

Im using OAF JDev 9.0.3 and i was getting this marvellous JBO-25030 error. My system has 4 tables, M1(father)->(Son)M2 ; M2-> M2 ; M2->M3; M2->M4; Ive create a row normally in the M3 in a master-detail page but M2 has always problems in the line "Row row = VO.createRow();". I trying chance the association , after i tryied the override in this blog but since im not in the ADF i get the error always too. Ive try create another AM and another PG and CO, error again. So i remove all association and viewlinks(VL) ive created automatically when i was creating the Entities. After i syncronize the all Entities again(theres nomore any VL) the page work. So i create the right ViewLink , manually, and it works PERFECTLY.
Hope helps someone like me.
PS(Sorry the bad english, :P).

Chris Muir said...

As you say hopefully this will be useful to somebody else - thanks for taking time out to write up your findings Daniel.