Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> JDeveloper problem with foreign keys

JDeveloper problem with foreign keys

From: Owen Gibbins <oweng_at_autoplan.ws>
Date: Thu, 12 Dec 2002 11:18:16 -0800
Message-ID: <pm5K9.225697$C8.621896@nnrp1.uunet.ca>


If there's a better group for me to be posting this issue, please let me know!

I'm having a problem with two tables linked by a foreign key. I created a new project to isolate the problem, and couldn't manage to fix it. I have two tables:

CREATE TABLE child(
id NUMBER,
name VARCHAR2(50) NOT NULL,
CONSTRAINT child_pk PRIMARY KEY(id));

CREATE TABLE parent(
id NUMBER,
child_id NUMBER,
title VARCHAR2(50) NOT NULL,
CONSTRAINT parent_pk PRIMARY KEY(id),
CONSTRAINT parent_child_fk FOREIGN KEY(child_id) REFERENCES child);

I created the business components for these tables, and altered the View Link ParentChildFKLink so that it exposes the accessor to ChildView from ParentView, naming this accessor ChildRow. I have the following view objects defined:

  ViewObject parentView = am.findViewObject("ParentView");   ViewObject childView = am.findViewObject("ChildView");

The following works just fine:

    parentView.reset();
    while(parentView.hasNext())
    {

      ParentViewRow parentRow = (ParentViewRow)parentView.next();
      ChildViewRow childRow = (ChildViewRow)parentRow.getChildRow();
      System.out.println(parentRow.getTitle() + "__" + ((childRow == null) ?
"(no child)" : childRow.getName()));

    }

Here's the problematic part of the program:

    ChildViewRow childRow = (ChildViewRow)childView.createRow();     ParentViewRow parentRow = (ParentViewRow)parentView.createRow();     parentRow.setChildID(childRow.getID().getSequenceNumber());     parentRow.setTitle("Sir");
    childRow.setName("Owen");

    childView.insertRow(childRow);
    parentView.insertRow(parentRow);
    am.getTransaction().commit();

I get an exception when committing the transaction, saying the foreign key constraint was violated. It shouldn't be, because I'm inserting the Child table row before the Parent row, correct? The only way I could get this to "work" was to do everything with the Child row first, commit the transaction, then deal with the parent row. Is this the way it will have to be done? The problem originally arose in a larger, more complex program, and to alter that program to work this way would be a whole lot of trouble.

Another thing is that if I do everything short of the commit statement, I would still expect to be able to call parentRow.getChildRow() and get the new Child row returned. I don't; I get null. Should this happen?

Thanks very much for any help!

Owen Gibbins Received on Thu Dec 12 2002 - 13:18:16 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US