Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Foreign Key constraint on commit with External Transaction:

ramanujam95Mar 22 2007 — edited Mar 23 2007
Foreign Key constraint on commit with External Transaction:

I have been trying to insert a record having a foreign key and failed to insert after trying with the following cases.

Table A{
colA1PK;
colA2FK; // Foreign key to target column Table B-> colB1PK.
colA3;
}

Table B{
colB1PK; -- Primary Key
}

Mapping Scenario 1:
-------------------

Class A{
AttrA1PK; // mapped to Table A -> colA1PK
AttrA2FK; // mapped to Table B -> colB1PK
AttrA3; // mapped to Table A -> colA3
B ObjectB; // one-to-one mapping to ClassB based on foreign key reference (read-only)
}

Class B{
AttrB1PK; // mapped to Table B -> colB1PK
}

With this scenario, when the external transaction issues a commit I get an exception: on colB1PK because toplink is trying to insert a record in Table B twice. Basically I could see insert statements getting executed twice.

Mapping Scenario 2:
-------------------

Class A{
AttrA1PK; // mapped to Table A -> colA1PK
AttrA2FK; // mapped to Table A -> colA2FK
AttrA3; // mapped to Table A -> colA3
B ObjectB; // one-to-one mapping to ClassB based on foreign key reference (read-only)
}

Class B{
AttrB1PK;
}

Now when I change the 'AttrA2FK;' to map to 'Table A -> colA2FK' I get Exception: java.lang.NullPointerException
at oracle.toplink.internal.descriptors.ObjectBuilder.addPrimaryKeyForNonDefaultTable(ObjectBuilder.java:115).

Mapping Scenario 3:
-------------------

Class A{
AttrA1PK; // mapped to Table A -> colA1PK
AttrA2FK; // mapped to Table B -> colB1PK
AttrA3; // mapped to Table A -> colA3
B ObjectB; // no mapping
}

Class B{
AttrB1PK;
}

Now when remove the one-to-one mapping and just map the foreign key to 'Table B -> colB1PK' toplink is inserting a row in 'Table A' before inserting into
'Table B' and I get a exception on foreign key constraint.


Having tried my ideas and also searched forum with no more clues I failed to overcome my problem.

Help will be appreciated.

thanks,
-Rama
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 20 2007
Added on Mar 22 2007
3 comments
2,011 views