0 Replies Latest reply on Apr 20, 2008 12:41 PM by siew_edward

    Cascade Persist - integrity contraint violated - parent key

    siew_edward Newbie

      Hi Seam experts,

      I have a common problem which I am not able to solve despite referring to some good references. Kindly let me know what went wrong. I am using seam 2.0.2CR1 with Oracle XE. Thanks in advance.

      I have 2 simple tables with a parent-child relationships:-

      CREATE TABLE "TEST" ( "TEST_ID" NUMBER(18,0), "TEST_NAME" VARCHAR2(50), CONSTRAINT "TEST_PK" PRIMARY KEY ("TEST_ID") ENABLE )
      
      CREATE TABLE "TEST_ITEM" ( "TEST_ITEM_ID" NUMBER(18,0), "TEST_ITEM_NAME" VARCHAR2(50), "TEST_ID" NUMBER(18,0) NOT NULL ENABLE, CONSTRAINT "TEST_ITEM_PK" PRIMARY KEY ("TEST_ITEM_ID") ENABLE, CONSTRAINT "TEST_ITEM_CON" FOREIGN KEY ("TEST_ID") REFERENCES "TEST" ("TEST_ID") ON DELETE CASCADE ENABLE )


      In the Test.java entity, I have the following declaration:-

      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "test") public Set<TestItem> getTestItems() { return this.testItems; }
      


      In the TestItem.java entity, I have the following declaration:-

      @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "TEST_ID", nullable = false) @NotNull public Test getTest() { return this.test; }


      In the TestHome.java entity home, I have the following code:-

      @Override public String persist(){ Test test = getInstance(); TestItem item = new TestItem(); item.setTestItemName("testing"); item.setTest(test); test.getTestItems().add(item); return super.persist(); }


      And finally, I am getting the following common error:-

      00:19:25,156 INFO [STDOUT] Hibernate: select * from ( select test0_.TEST_ID as TEST1_11_, test0_.TEST_NAME as TEST2_11_ from IMPORTSTS.TEST test0_ ) where rownum <= ? 00:19:30,343 INFO [Authenticator] authenticating demo 00:19:36,484 INFO [STDOUT] Hibernate: select IMPORTSTS.SHIPMENT_SEQ.nextval from dual 00:19:36,515 INFO [STDOUT] Hibernate: select IMPORTSTS.SHIPMENT_VARIABLE_SEQ.nextval from dual 00:19:36,546 INFO [STDOUT] Hibernate: insert into IMPORTSTS.TEST (TEST_NAME, TEST_ID) values (?, ?) 00:19:36,546 INFO [STDOUT] Hibernate: insert into IMPORTSTS.TEST_ITEM (TEST_ID, TEST_ITEM_NAME, TEST_ITEM_ID) values (?, ?, ?) 00:19:36,562 WARN [JDBCExceptionReporter] SQL Error: 2291, SQLState: 23000 00:19:36,562 ERROR [JDBCExceptionReporter] ORA-02291: integrity constraint (IMPO RTSTS.TEST_ITEM_CON) violated - parent key not found