0 Replies Latest reply on Jul 25, 2003 8:22 AM by cvaughan

    Foreign Key Question

    cvaughan Newbie

      I am using Oracle 9i and JBoss 4.0. I am trying to develop an EJB application that uses CMR relationships between tables.

      One of the problems I am having is with foreign key constraints where a foreign key maps to a primary key of another table.

      JBoss first calls the ejbCreate method and generates an insert statement that consists of the all the relevant fields as well as the CMR field that has been defined as the foreign key.

      The problem is that Oracle generates a foreign key constraint error because the CMR field is NULL. The ejbPostCreate() is never called so the foreign key never gets set.

      The only way have been able to fix this is by setting my foreign key to accept nulls, setting the "DEFERRABLE INITIALLY DEFERRED" constraint in Oracle for the foreign key and creating CMF fields where the foreign key is set in ejbCreate. I would rather I did not have to do any of the above

      My question is does anyone know if there is an option in JBoss 4 that defers an Insert only after the ejbPostCreate method has been called. It seems a simple thing for JBoss to do. I don't see why is has to first insert a record then set the relationship in ejbCreatePost and then issue an update command to update the foreign key. All of this could be done in one simple transaction not two.

      Thanks.