Using FOreign key constraints on tables in database.

I am student and novice in the field of ORACLE and PL/SQL and Database Creation. I had created a database consisting tables and got problem while applying foreign key constraints.
CUST_MSTR
CREATE TABLE "DBA_BANKSYS"."CUST_MSTR"("CUST_NO" VARCHAR2(10),
"FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25), "LNAME" VARCHAR2(25),
"DOB_INC" DATE NOT NULL,      "OCCUP" VARCHAR2(25), "PHOTOGRAPH" VARCHAR2(25),
"SIGNATURE" VARCHAR2(25), "PANCOPY" VARCHAR2(1),      "FORM60" VARCHAR2(1));
(CUST_NO is PRIMARY KEY, )
-- EMP_MSTR
CREATE TABLE "DBA_BANKSYS"."EMP_MSTR"("EMP_NO" VARCHAR2(10),
"BRANCH_NO" VARCHAR2(10), "FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25),
"LNAME" VARCHAR2(25), "DEPT" VARCHAR2(30), "DESIG" VARCHAR2(30));
(EMP_NO is primary key )
--NOMINEE_MSTR
CREATE TABLE "DBA_BANKSYS"."NOMINEE_MSTR"("NOMINEE_NO" VARCHAR2(10),
"ACCT_FD_NO" VARCHAR2(10), "NAME" VARCHAR2(75), "DOB" DATE,
RELATIONSHIP" VARCHAR2(25));
(NOMINEE_NO is primary key )
--ADDR_DTLS
CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
"CODE_NO" VARCHAR2(10),      "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
"ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
"PINCODE" VARCHAR2(6));
( ADDR_NO is primary key )
Problem: I want to apply foreign key constraints on ADDR_DTLS table so that Before inserting value in ADDR_DTLS table it must check, VALUE in ADDR_DTLS.CODE_NO must be PRESENT either in attribute value CUST_MSTR.CODE_NO or EMP_MSTR.CODE_NO or NOMINEE_MSTR.CODE_NO table .
I applied the foreign key constraints using this syntax
CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
"CODE_NO" VARCHAR2(10),      "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
"ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
"PINCODE" VARCHAR2(6),
constraints fk_add foreign key CODE_NO references CUST_MSTR. CODE_NO,
constraints fk_add1 foreign key CODE_NO references EMP_MSTR. CODE_NO,
constraints fk_add2 foreign key CODE_NO references NOMINEE_MSTR.CODE_NO);
(foreign key)
ADDR_DTLS.CODE_NO ->CUST_MSTR.CUST_NO
ADDR_DTLS.CODE_NO ->NOMINEE_MSTR.NOMINEE_NO
ADDR_DTLS.CODE_NO ->BRANCH_MSTR.BRANCH_NO
ADDR_DTLS.CODE_NO ->EMP_MSTR.EMP_NO
When I applied foreign key constraints this way, its gives a error called foreign key constraints violation. (I understand that, its searches the attribute value of ADDR_DTLS.CODE_NO in all the three tables must be present then the value will be inserted. But I want, if the value is in any of the three table then its should insert the value or its gives an error.)
Please help me out, though i put the question and i want too know how to apply the forign key in this way. and is there any other option if foreign key implementation is not pssible.

If you are on 11g you can use ON DELETE SET NULL:
CREATE TABLE addr_dtls
( addr_no          NUMBER(6)  CONSTRAINT addr_pk PRIMARY KEY
, addr_cust_no     CONSTRAINT addr_cust_fk    REFERENCES cust_mstr    ON DELETE SET NULL
, addr_emp_no      CONSTRAINT addr_emp_fk     REFERENCES emp_mstr     ON DELETE SET NULL
, addr_nominee_no  CONSTRAINT addr_nominee_fk REFERENCES nominee_mstr ON DELETE SET NULL
, addr_type        VARCHAR2(1)
, addr1            VARCHAR2(50)
, addr2            VARCHAR2(50)
, city             VARCHAR2(25)
, state            VARCHAR2(25)
, pincode          VARCHAR2(6) );In earlier versions you'll need to code some application logic to do something similar when a parent row is deleted, as otherwise the only options are to delete the dependent rows or raise an error.
btw table names can be up to 30 characters and don't need to end with MSTR or DTLS, so for example CUSTOMERS and ADDRESSES might be more readable than CUST_MSTR and ADDR_DTLS. Also if the Customer/Employee/Nominee PKs are generated from a sequence they should be numeric.
Edited by: William Robertson on Aug 15, 2010 6:47 PM

Similar Messages

  • FOREIGN KEY CONSTRAINT 의 MASTER TABLE NAME 의 확인

    제품 : ORACLE SERVER
    작성날짜 : 1995-11-02
    FOREIGN KEY CONSTRAINT 의 MASTER TABLE NAME 의 확인
    ===================================================
    다음은 FOREIGN KEY CONSTRAINT 이름으로 REFERENCE 하는 TABLE
    (MASTER TABLE)을 찾는 SQL SCRIPT이다.
    col Primary_key_table format a20
    col Constraint_name format a20
    select a.object_name Primary_Key_table,
    c.name Constraint_name
    from dba_objects a,
    sys.cdef$ b,
    sys.con$ c
    where c.name = 'EMP_FOREIGN_KEY' -- CONSTRAINT NAME
    and b.con# = c.con#
    and b.robj# = a.object_id
    /

    The set of constraints as you show it is valid, but will likely result in a lot of violations since both child columns are larger than the parent. The Oracle 2256 error has nothing to do with data validation, nor with the different lengths of the columns. The documentation says
    02256, 00000, "number of referencing columns must match referenced columns"
    // *Cause: The number of columns in the foreign-key referencing list is not
    //         equal to the number of columns in the referenced list.
    // *Action: Make sure that the referencing columns match the referenced
    //          columns.Look at the actual statement that the client ran. It will be different than the one you posted. one of the two column lists will have more columns than the other.

  • FOREIGN KEY CONSTRAINT의 MASTER TABLE을 REFERENCE하는 TABLE 찾기

    제품 : SQL*PLUS
    작성날짜 : 2003-12-17
    FOREIGN KEY CONSTRAINT의 MASTER TABLE을 REFERENCE하는 TABLE 찾기
    ================================================================
    Master table 이 dept2일 때, 이 테이블을 참조하는 table들을 찾는 SQL
    select x.table_name "reference table"
    from
    (select distinct r_constraint_name,table_name
    from all_constraints
    where constraint_type='R' ) x, all_constraints a
    where a.table_name = 'DEPT2'
    and x.r_constraint_name = a.constraint_name;

  • Foreign keys in source tables (sybase database)

    Hi,
    Foreign key / primary key constraints are not captured / converted in oracle model nor they are generated.
    I am migrating sybase database tables to oracle. These tables have foreign keys, but while capturing and then converting the table to oracle model and then generating, these foreign keys are not present in the ddl script.
    In the source connection ( in the tool) to the sybase database, these keys are shown,
    and logically when the generation is done for table, the foreign / primary key syntax should be present in the ddl generated
    Am more worried about the foreign key not getting converted
    Please help
    Regards

    Hello,
    do you have a very simple example showing this behaviour ?
    What is your sybase version ? And what about Sqldev version ?
    Do you tested migration with offline method ?
    As testcase, a emp and dept schema with foreign key should be ideal.
    Thanks
    Regards,
    Marcello

  • FOREIGN KEY Constraint And Table Lock

    According to Db Concepts on Data Integrity->Types of Integrity Contraints->Referential Integrity Constraints, if the FK column is not indexed, delete/update of parent table would cause child table share locked.
    I can understand the reason behind this behaviour because if parent's PK is modified but not commited yet, we don't want another transaction to insert/update the child's FK column to use the deleted parent PK value and this requires a table share lock.
    The problem is, I don't understand why if the child's FK is indexed, no table share lock is acquired. The same condition could happen and we still need to prevent another transaction from using the uncommitted deleted PK in parent as the child's FK.
    Appreciate and advice.

    hi
    When PK column change, Oracle is going to have to do a
    referential integrity check on any referenced columns ,in
    the absence of an index on the child end of the foreign
    key, that would seem to result in a full table scan of the table which cause locks the entire table for any
    Delete or Update on Parent table.
    Khurram

  • How to fetch column data using foreign key in adf table ?

    I have created a adf table using a view that has a group id and user id column. I want to display the user name ( from user table) and group name from group table. I had created view links to the corresponding tables from the user_group view ( whose iterator is used to render the table).
    It sort of works. I dragged the user name from the embedded user iterator in user_group iterator. It does find the correct user name but if I have more than one row, it displays the user name of the last row user in all rows !
    Is there a solution to this problem ?

    Well, I saw in the view query for the association view ( for Many-Many) that the SQL already had the joins with the two ( master) tables to the association table. So I went ahead and added the descriptive columns to the select clause. Then the selected columns showed up in the attribute list by themselves ( without my intervention). So far so good.
    Then I recreated the adf table attribute by dragging these newly selected attribute to the page. I still see that the value of the attribute is the same in all the rows - this time it is the value for the FIRST row. It doesn't correspond to the foreign key for that particular row.
    IS THIS A BUG ? Has anyone else ever done this ?

  • Import table data in right order to avoid violating foreign key constraints

    Gentlemen
    I am trying to import table data into an existing 10g schema using datapump import in table mode.
    However, in order to avoid violating foreign key constraints, the tables must be loaded in a specified order. I tried specifying the order in the TABLES parameter:
    TABLES=table1,table2,table3 etc.
    However, datapump seems to chose its own order leading to errors like the following:
    ORA-31693: Table data object "SCHEMAX"."TABLE3" failed to load/unload and is being skipped due to error:
    ORA-02291: integrity constraint (SCHEMAX.TABLE3_TABLE1#FK) violated - parent key not found
    I want to try to avoid having to disable all foreign keys because there are hundreds of them.
    Any advice?
    Yours
    Claus Jacobsen, Denmark

    Thanks Anantha.
    Since I am only loadding data (the constraints are already defined in the target database), I am not sure whether this approach would work. Meanwhile I have solved the problem of moving data from one system to another using another, tedious and far from elegant approach that I would prefer to not eloborate on:-)
    However, I have also discovered another probable reason why the foreign key constraints were violated, other than wrong order of table data loading. It turns out almost every single table in the schema contains a trigger supposed to generate a unique row ID from a sequence on insert such as:
    CREATE OR REPLACE TRIGGER "SCHEMAX"."TABLEX#B_I_R"
    BEFORE INSERT
    ON TABLEX
    FOR EACH ROW
    DECLARE
    BEGIN
    SELECT tablex_seq.nextval INTO :NEW.ID FROM dual;
    END;
    If the import mechanism fires this trigger, and the sequences in the source and the target systems are not synchronized, then I guess that referred records a more than likely to end up with wrong ID's compared to the row ID's in the referring rows?
    Spooky. Anybody can confirm this theory?
    Yours
    Claus
    Message was edited by:
    user586249

  • Publish: dropping index when it is used for foreign key constraint enforcement

    Hi,
    I'm trying to update a target schema from a reference database via Publish. Among the changes to apply, there's an index that needs to be dropped. Since it's linked to a foreign key constraint, it cannot be deleted unless the foreign key is temporarily dropped
    (I saw somewhere that disabling the foreign key should be enough but it doesn't seem to work either).
    Since there are other changes to be made on the same table, this foreign key also has to be dropped before the script can delete the table and re-create it. This part of the script is correctly generated. The problem is that this part appears after the 'DROP
    INDEX' instruction.
    So when generating the update script, SSDT tries to drop the index BEFORE dropping the foreign key. And I can't drop the foreign key in my custom pre-deployment script, otherwise the update script would fail when trying to delete it again.
    Shouldn't SSDT be smart enough to drop the constraint before the index? Is it a bug or did I forget to set an option? If it's not a bug, what can I do apart from doing it manually?
    Thank you for your help

    Hi Elsa,
    That sounds like a bug. Could you please file a Connect issue for this at
    https://connect.microsoft.com/SQLServer/feedback/CreateFeedback.aspx using the category "Developer Tools (SSDT, BIDS, etc.)"? We're trying to track all bugs through
    Connect so that you can tell when we have fixed the issue and we can request more information.
    A workaround for this issue might be to write a pre-deployment script for your project to drop the foreign key prior to deployment. A pre-deployment script can be added to your project by right-clicking on the
    project in solution explorer and then clicking on Add > Script... and selecting Pre-Deployment Script from the list.
    Thanks!

  • Is this a BUG???  Database Export not including Foreign Key Constraints

    I'm using SQL Developer 1.5.4 with both the 59.47 and 59.59 patches installed. I want to do a database export from a 10g XE schema, and include all objects in the resulting DDL. So, I select ALL the checkboxes in the export wizard and when I get to Step 3 to specify objects, I don't see any of my constraints in the listbox... no foreign key constraints, no primary key constraints, no check constraints, nothing. Is this a bug, or is there a workaround, or what could I possibly be doing wrong? We want to be able to use the database export feature to easily transport and track modifications to our entire schema using source control compare.
    Any help or alternate suggestions would be apprieciated.
    Thanks,
    Matt

    Thanks skutz, we just figured that out this morning. Also, it should be noted that you need to be logged in as the owner of the schema otherwise selecting nothing in the filter will give you nothing, but selecting items in the filter will give you those items even if you're not connected as the schema owner. I wonder if that is the detail of the Bug 8679318.
    Edited by: mattsnyder on Jul 14, 2009 9:24 AM

  • Foreign Key Constraint Failure on Self-Referencing Table

    In a recent data deletion project, I ran into a problem where Oracle allowed for a record (the parent) to be deleted when there still existed a child record in the same table which referred to the parent.
    An abbreviated version of the table is as follows:
    create table test (
    template_id number not null,
    customer_id number null,
    parent_id number null,
    constraint pk_test primary key (template_id),
    constraint r_parent foreign key (parent_id) references test (template_id));
    The parent and child records are as follows:
    Parent: template_id = 100, customer_id = 200, parent_id = null
    Child: template_id = 101, customer_id = null, parent_id = 100
    Records were deleted from this table using:
    DELETE FROM test WHERE customer_id = 200;
    When this statement is executed, is it being executed as part of 155 delete statements using PL/SQL, and tens of thousands of records from 155 tables are being deleted. These delete statements have been ordered taking into account foreign key constraints. All 155 statements are being deleted in a single transaction. The delete statement above was the 23rd statement of the set to be executed. I would have expected when this delete statement was executed, an error would have been thrown. However, all 155 delete statements successfully complete, and after committing the results, the child record above still exists in the DB as an orphan. I also tried executing the first 23 statements manually in SQL*Plus (still one transaction), and the problem still occurs: the parent is deleted and the child is orphaned.
    If I execute the very simple example above, I do indeed get an referential constraint error.
    Has anyone ever encountered this situation? And does anyone have any ideas how to go about troubleshooting this problem. We need to know the cause of this, as we have a small handful of table with a similar self-referential foreign key constraint set-up.
    Thank you very much in advance,
    Mark

    First of all, the very simple example that I outlined above I have already tried and it worked: when I attempted to delete the parent a referential integrity error was thrown as one would expect. This small example was my test case to see if I could reproduce what I'm seeing in our application in a more manageable and demonstrable example. But as it worked, I'm still perplexed in reconciling the differences between what I'm seeing in our application (which I can't demonstrate in this help group) and the test case. When I used the test case in my first posting in this thread, I used it to help describe the problem I'm encountered, even though that small example works.
    Below is more of the table you've asked for.
    OWNER           CONSTRAINT_NAME          CONSTRAINT_TYPE     TABLE_NAME     SEARCH_CONDITION     R_OWNER            R_CONSTRAINT_NAME     DELETE_RULE     STATUS          DEFERRABLE            DEFERRED         VALIDATED     GENERATED     BAD     RELY     LAST_CHANGE           INDEX_OWNER  INDEX_NAME       INVALID     VIEW_RELATED
    "DOCPADMIN"     "R_TEMPLATE_PARENT"     "R"             "DCR_TEMPLATE"      (null)                  "DOCPADMIN"     "XPKDCR_TEMPLATE"     "NO ACTION"  "ENABLED"   "NOT DEFERRABLE"    "IMMEDIATE"  "VALIDATED"      "USER NAME"     (null)     (null)     "2010-01-13 19:01:21"     (null)        (null)         (null)       (null)
    "DOCPADMIN"     "XPKDCR_TEMPLATE"       "P"             "DCR_TEMPLATE"      (null)                       (null)     (null)                      (null)          "ENABLED"     "NOT DEFERRABLE"    "IMMEDIATE"      "VALIDATED"     "USER NAME"     (null)     (null)     "2010-01-13 15:48:31"     (null)     "XPKDCR_TEMPLATE"   (null)     (null)Overall, I haven't said that Oracle's FK mechanism is broken. What I've said is that I've got a situation that I'm trying to understand. My first attempt at my test case didn't work because the test case worked as it should. I'm trying to figure out another course of action to try and figure this situation out.

  • Creating a foreign key constraint on a synonym of table in another schema.

    Hi,
    I am having two user operapps and oper
    owner of table po_vendors is operapps ,i have created a synonym in oper with select permission.
    now i am trying to create a foreign key.
    ALTER TABLE OPS_BR_VENDORS ADD ( FOREIGN KEY (VENDOR_ID) REFERENCES PO_VENDORS (VENDOR_ID));
    the bolded po_vendors is the synonym for the table po_vendors in operapps.
    i am getting the below error message.
    SQL> ALTER TABLE OPS_BR_VENDORS ADD ( FOREIGN KEY (VENDOR_ID) REFERENCES PO_VENDORS (VENDOR_ID));
    ALTER TABLE OPS_BR_VENDORS ADD ( FOREIGN KEY (VENDOR_ID) REFERENCES PO_VENDORS (VENDOR_ID))
    ERROR at line 1:
    ORA-01031: insufficient privileges.
    i have given dba privileges to oper user.
    Please advice.

    1) You cannot create a constraint on a synonym. You have to specify a physical table (i.e. OPERAPPS.PO_VENDORS)
    2) The owner of the OPS_BR_VENDORS table will need to have the REFERENCES permission on the PO_VENDORS table granted directly (not via a role).
    Justin

  • Query the name of the parent table in a foreign key constraint

    Hello,
    Does anyone know how to query for the parent table name in a foreign key constraint? I don't see that relationship in ALL_CONS_COLUMNS or ALL_CONSTRAINTS.
    Thanks in advance,
    Michael

    or try this...
    SELECT rc.TABLE_NAME "PK_Table_Name",cc.TABLE_NAME "FK_Table_Name",
           case when cc.column_name = rc.column_name
                then c.TABLE_NAME || '(' || cc.COLUMN_NAME || ')'
                else r.TABLE_NAME || '(' || rc.COLUMN_NAME || ') = ' ||c.TABLE_NAME || '(' || cc.COLUMN_NAME || ')' end as "TABLE_NAME(COLUMN_NAME)"
    from all_constraints c,
         all_constraints r,
         all_cons_columns cc,
         all_cons_columns rc
    WHERE
         r.table_name = upper('emp')
    and      c.CONSTRAINT_TYPE = 'R'
    and     c.R_OWNER = r.OWNER
    and     c.R_CONSTRAINT_NAME = r.CONSTRAINT_NAME
    and     c.CONSTRAINT_NAME = cc.CONSTRAINT_NAME
    and     c.OWNER = cc.OWNER
    and     r.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
    and     r.OWNER = rc.OWNER
    and     cc.POSITION = rc.POSITION
    ORDER BY r.TABLE_NAME;

  • How we relate two tables using foreign key(fk)?

    hi to all,
        what are the conditions has to follow to relate two tables.I.e.,
    the two tables have same primary keys(pk). if we relate these two tables in one table the pk and fk will be the same then how that table in active.

    Hi
    To relate two tables..we have foreign key relationship.
    In one table v have primary key and in the second table, the same key is foreign key for that table..
    To relate two tables, we can use JOINS
    If there is already a suitable foreign key between two tables used in the view, these tables can be linked with a join condition from this foreign key.
    Create a view on tables TAB1 and TAB2. TAB1 is the primary table of the view. TAB2 is the secondary table of the view. TAB1 is the check table for TAB2. The foreign key fields are assigned to the check table fields as follows:
    TAB1-FIELD_A assigned to TAB2-FIELD_1
    TAB1-FIELD_A assigned to TAB2-FIELD_1
    The join condition of the view generated from the foreign key is then:
    CREATE VIEW ... AS SELECT ... WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = TAB1-FIELD_B.
    Join conditions can also be copied from generic and constant foreign keys. If a constant is assigned to a field in the foreign key, it is also assigned to the field in the join condition. There is no join condition for a generic relationship in the foreign key.
    The foreign key between tables TAB1 (check table) and TAB2 (foreign key table) is defined as follows:
    TAB1-FIELD_A assigned to TAB2-FIELD_1
    TAB1-FIELD_B generic
    TAB1-FIELD_C assigned to constant ‘C’
    The join condition for the view generated from the foreign key is in this case:
    CREATE VIEW ... AS SELECT ... WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = ‘C’.
    Hope it helps
    Reward if useful.

  • Foreign keys to same table / Who columns in User table???

    Hi All,
    We are designing a database for our client and we are using common columns in all tables like CreatedBy and UpdatedBy which are foreign keys to USER table. My question is can we use these two columns in USER table and have the foreign key constraints to the same tables?
    USER table script will look like following..
    CREATE TABLE XX_USER
         User_ID                              VARCHAR2(10)
    ,     CreatedBy                         NUMBER(10)
    ,     UpdatedBy                         NUMBER(10)
    ,     User_Name                         VARCHAR2(100)     NOT NULL
    ,     Designation                         VARCHAR2(100)     NOT NULL
    ,     CONSTRAINT USER_ISACTIVE_CHECK CHECK (Is_Active in ('Y', 'N'))
    ,     CONSTRAINT USER_KEY PRIMARY KEY (User_ID),
    ,     CONSTRAINT USER_CREATED_BY FOREIGN KEY (CREATED_BY)
         REFERENCES XX_USER (USER_ID)
    ,     CONSTRAINT USER_UPDATED_BY FOREIGN KEY (UPDATED_BY)
         REFERENCES XX_USER (USER_ID)
    );I think what I am doing (the above script) is not correct. Could someone please suggest me how can solve this issue?
    Thanks in advance,
    Oraebs

    user8644385 wrote:
    We are designing a database for our client and we are using common columns in all tables like CreatedBy and UpdatedBy which are foreign keys to USER table. My question is can we use these two columns in USER table and have the foreign key constraints to the same tables?You can. After fixing synatx errors:
    SQL> CREATE TABLE XX_USER
      2  (
      3   User_ID        VARCHAR2(10)
      4  , CreatedBy     NUMBER(10)
      5  , UpdatedBy     NUMBER(10)
      6  , User_Name     VARCHAR2(100) NOT NULL
      7  , Designation   VARCHAR2(100) NOT NULL
      8  , Is_Active     VARCHAR2(1)
      9  , CONSTRAINT USER_ISACTIVE_CHECK CHECK (Is_Active in ('Y', 'N'))
    10  , CONSTRAINT USER_KEY PRIMARY KEY (User_ID)
    11  , CONSTRAINT USER_CREATED_BY FOREIGN KEY (CreatedBy)
    12       REFERENCES XX_USER(USER_ID)
    13  , CONSTRAINT USER_UPDATED_BY FOREIGN KEY (UpdatedBy)
    14       REFERENCES XX_USER(USER_ID)
    15  )
    16  /
    Table created.
    SQL> Now USER_ID is a string while CreatedBy/UpdatedBy is a number. Even though it is allowed, it limits USER_ID to numeric strings and causes implicit conversions while validating. So I would change CreatedBy/UpdatedBy data type to VARCHAR2(10).
    SY.

  • Wrong order foreign key constraints

    Hi,
    i have problems with non-deferred foreing key constraints:
    I have a table "PERSON" and a table "ADRESSE" which has a foreign key
    to "PERSON". Both tables have primary keys with two columns.
    In the mappings I use application identity. The mappings are generated by
    xdoclet.
    We cannot use deferred constraint because we have to support following
    databases: Oracle, Firebird, MS SQL, DB2.
    I tested the mappings with Oracle and Firebird and got this exception
    (with SQL Trace):
    5602 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (1 errors)>
    [15 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
    EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
    POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
    ?, ?, ?, ?, ?, ?) [params=(int) 1, (String) [email protected], (String)
    04941 183742, (int) 12761, (int) 1, (int) 1, (String) 0171 2846751,
    (String) Oldenburg, (int) 12760, (String) 26129, (int) 1, (null) null,
    (String) Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=0]
    5602 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
    [0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
    EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
    POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
    ?, ?, ?, ?, ?, ?) [params=(int) 3, (null) null, (null) null, (int) 12764,
    (int) 1, (int) 0, (null) null, (String) Sylt, (int) 12759, (String) 25980,
    (int) 0, (null) null, (String) Stephanstra__e 47, (String) 04651 19283]
    [reused=1]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
    [0 ms] executing prepstmnt 13390902 INSERT INTO VAMP.PERSON (ANREDEID, ID,
    KUNDENNR, LOESCHBEMERKUNG, MANDANTID, NAME1, NAME2, PERSONENDATUM,
    PERSONENORT, TYP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(null)
    null, (int) 12759, (String) 9999452800, (null) null, (int) 1, (String)
    Horstmann, (String) Manfred, (Timestamp) 1959-03-10 00:00:00.381, (String)
    Flensburg, (int) 1] [reused=0]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
    [0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
    EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
    POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
    ?, ?, ?, ?, ?, ?) [params=(int) 1, (String) [email protected], (String)
    04941 183742, (int) 12763, (int) 1, (int) 1, (String) 0171 2846751,
    (String) Oldenburg, (int) 12759, (String) 26129, (int) 1, (null) null,
    (String) Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=2]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
    [0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
    EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
    POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
    ?, ?, ?, ?, ?, ?) [params=(int) 3, (null) null, (null) null, (int) 12762,
    (int) 1, (int) 0, (null) null, (String) Sylt, (int) 12760, (String) 25980,
    (int) 0, (null) null, (String) Stephanstra__e 47, (String) 04651 19283]
    [reused=3]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
    [0 ms] executing prepstmnt 13390902 INSERT INTO VAMP.PERSON (ANREDEID, ID,
    KUNDENNR, LOESCHBEMERKUNG, MANDANTID, NAME1, NAME2, PERSONENDATUM,
    PERSONENORT, TYP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(null)
    null, (int) 12760, (String) 9999452801, (null) null, (int) 1, (String)
    Horstmann, (String) Christine, (Timestamp) 1972-03-10 00:00:00.381,
    (String) Erfurt, (int) 1] [reused=1]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
    [0 ms] executing prepstmnt 11320634 INSERT INTO VAMP.NATPERSON
    (ANZAHLKINDER, ARBEITGEBERID, BEITRAGSSATZ, BERUFID, BRANCHEID,
    FAMILIENSTAND, FAMSTANDSEIT, FINANZAMTID, GEBIETSFREMDERAWG, GUETERSTAND,
    IDBEHOERDE, IDNR, KIRCHENSTEUER, KVID, MANDANTID, PERSONID, PRIVATKV,
    STAAT, STEUERBERATERID, STEUERKLASSE, STEUERNR, STEUERTARIF, TITEL) VALUES
    [params=(int) 0, (null) null, (double) 0.0, (null) null, (int) 12410,
    (int) 2, (Timestamp) 1991-12-12 00:00:00.381, (null) null, (int) 0, (int)
    3, (null) null, (null) null, (int) 0, (int) 12576, (int) 1, (int) 12760,
    (int) 0, (null) null, (null) null, (int) 0, (null) null, (int) 1, (null)
    null] [reused=0]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
    [0 ms] executing prepstmnt 11320634 INSERT INTO VAMP.NATPERSON
    (ANZAHLKINDER, ARBEITGEBERID, BEITRAGSSATZ, BERUFID, BRANCHEID,
    FAMILIENSTAND, FAMSTANDSEIT, FINANZAMTID, GEBIETSFREMDERAWG, GUETERSTAND,
    IDBEHOERDE, IDNR, KIRCHENSTEUER, KVID, MANDANTID, PERSONID, PRIVATKV,
    STAAT, STEUERBERATERID, STEUERKLASSE, STEUERNR, STEUERTARIF, TITEL) VALUES
    [params=(int) 0, (null) null, (double) 0.0, (int) 12362, (int) 12378,
    (int) 2, (Timestamp) 1991-12-12 00:00:00.381, (null) null, (int) 0, (int)
    3, (null) null, (null) null, (int) 0, (int) 12576, (int) 1, (int) 12759,
    (int) 0, (null) null, (null) null, (int) 0, (null) null, (int) 1, (null)
    null] [reused=1]
    5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
    errors)> [16 ms] rollback
    5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
    errors)> return
    5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
    errors)> [0 ms] close
    com.solarmetric.jdbc.ReportingSQLException: ORA-02291: integrity
    constraint (VAMP.ADRESSE_PS) violated - parent key not found
    {prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART, EMAIL, FAXNR,
    ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ, POSTADRESSE,
    POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
    ?, ?) [params=(int) 1, (String) [email protected], (String) 04941
    183742, (int) 12761, (int) 1, (int) 1, (String) 0171 2846751, (String)
    Oldenburg, (int) 12760, (String) 26129, (int) 1, (null) null, (String)
    Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=0]} [code=2291,
    state=23000]
         at
    com.solarmetric.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:124)
         at
    com.solarmetric.jdbc.LoggingConnectionDecorator.access$600(LoggingConnectionDecorator.java:19)
         at
    com.solarmetric.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:728)
         at
    com.solarmetric.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:362)
    How can I force it to insert in the table "NATPERSON" first and then in
    the table "ADRESSE"?
    I use following JDBC-drivers:
    Firebird: 1.5.5
    Oracle: 9.2.0.1.0
    My property file:
    <!-- standard properties for all dbms -->
    <prop key="kodo.LicenseKey">LICENSE KEY REMOVED</prop>
    <prop key="kodo.ConnectionFactoryProperties">MaxCachedStatements=150,
    MaxActive=50, MaxIdle=50</prop>
    <prop key="kodo.FetchBatchSize">200</prop>
    <prop key="kodo.DataCache">true(CacheSize=5000)</prop>
    <prop key="kodo.RemoteCommitProvider">sjvm</prop>
    <prop key="kodo.jdbc.MappingFactory">metadata</prop>
    <prop key="kodo.jdbc.ForeignKeyConstraints">true</prop>
    <prop key="kodo.jdbc.SchemaFactory">native</prop>
    <prop
    key="javax.jdo.PersistenceManagerFactoryClass">kodo.jdbc.runtime.JDBCPersistenceManagerFactory</prop>
    <prop key="javax.jdo.option.Optimistic">true</prop>
    <!-- oracle connection properties -->
    <prop key="kodo.jdbc.DBDictionary">oracle</prop>
    <prop
    key="javax.jdo.option.ConnectionDriverName">oracle.jdbc.driver.OracleDriver</prop>
    <prop key="javax.jdo.option.ConnectionURL">..</prop>
    <prop key="javax.jdo.option.ConnectionUserName">..</prop>
    <prop key="javax.jdo.option.ConnectionPassword">..</prop>
    <prop key="kodo.jdbc.SequenceFactory">native</prop>
    <prop key="kodo.jdbc.Schemas">..</prop>
    <!-- firebird connection properties
    <prop key="kodo.jdbc.DBDictionary">kodo.jdbc.sql.FirebirdDictionary</prop>
    <prop
    key="javax.jdo.option.ConnectionDriverName">org.firebirdsql.jdbc.FBDriver</prop>
    <prop key="javax.jdo.option.ConnectionURL">..</prop>
    <prop key="javax.jdo.option.ConnectionUserName">..</prop>
    <prop key="javax.jdo.option.ConnectionPassword">..</prop>
    <prop key="kodo.jdbc.SequenceFactory">native(TableName=SYSDUAL,
    Format="SELECT GEN_ID({0},1) FROM {1}")</prop>
    -->
    My database schema looks like this:
    TABLE PERSON
    FIELD MANDANTID (SMALLINT REQUIRED COMMENT (""))
    FIELD ID (AUTOINC COMMENT (""))
    FIELD TYP (SMALLINT REQUIRED COMMENT (""))
    FIELD KUNDENNR (CHAR(15) COMMENT ("Kundennummer"))
    PRIMARY KEY
    FIELD MANDANTID
    FIELD ID
    FOREIGN KEY MD
    TABLE MANDANT
    FIELD MANDANTID
    INDEX KDNR
    FIELD MANDANTID
    FIELD KUNDENNR
    UNIQUE
    TABLE ADRESSE
    FIELD MANDANTID (SMALLINT REQUIRED COMMENT (""))
    FIELD ID (AUTOINC COMMENT (""))
    FIELD PERSONID (LONGINT REQUIRED COMMENT (""))
    PRIMARY KEY
    FIELD MANDANTID
    FIELD ID
    FOREIGN KEY PS
    TABLE PERSON
    FIELD MANDANTID
    FIELD PERSONID
    My metadata looks like this:
    <class name="PersonDO"
    identity-type="application"
    objectid-class="com.elaxy.vamp.dom.person.PersonDOId"
    persistence-capable-superclass="com.elaxy.vamp.dom.AbstractDO">
    <extension vendor-name="kodo"
    key="jdbc-class-ind"
    value="metadata-value">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-class-ind/column"
    value="TYP">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-class-ind-value"
    value="-1">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-class-map"
    value="base">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-class-map/table"
    value="PERSON">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map"
    value="value">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map/column"
    value="ID">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map"
    value="value">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map/column"
    value="MANDANTID">
    </extension>
    <field name="kundenNr"
    persistence-modifier="persistent">
    </field>
    <field name="adressen"
    persistence-modifier="persistent">
    <collection
    element-type="com.elaxy.vamp.dom.person.AdresseDO">
    </collection>
    <extension vendor-name="kodo"
    key="jdbc-field-map"
    value="one-many">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-map/ref-column.MANDANTID"
    value="MANDANTID">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-map/ref-column.ID"
    value="PERSONID">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-map/table"
    value="ADRESSE">
    </extension>
    </field>
    .. fields ..
    </class>
    <class name="AdresseDO"
    identity-type="application"
    objectid-class="com.elaxy.vamp.dom.person.AdresseDOId"
    persistence-capable-superclass="com.elaxy.vamp.dom.AbstractDO">
    <extension vendor-name="kodo"
    key="jdbc-class-map"
    value="base">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-class-map/table"
    value="ADRESSE">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-sequence-name"
    value="ADRESSE_SEQ">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map"
    value="value">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map/column"
    value="ID">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map"
    value="value">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map/column"
    value="MANDANTID">
    </extension>
    .. fields ..
    </class>
    Many thanks,
    Jan

    Marc
    This is a part of the output from the "schemagen" tool:
    <schemas>
    <schema name="VAMP">
    <table name="ADRESSE">
    <pk name="ADRESSE_PRIMARY">
    <on column="ID"/>
    <on column="MANDANTID"/>
    </pk>
    <column name="ADRESSART" type="decimal" type-name="NUMBER"
    size="5"/>
    <column name="EMAIL" type="varchar" type-name="VARCHAR2"
    size="30"/>
    <column name="FAXNR" type="varchar" type-name="VARCHAR2"
    size="25"/>
    <column name="ID" type="decimal" type-name="NUMBER"
    not-null="true" size="10"/>
    <column name="LAND" type="decimal" type-name="NUMBER"
    size="10"/>
    <column name="MANDANTID" type="decimal" type-name="NUMBER"
    not-null="true" size="5"/>
    <column name="MELDEADRESSE" type="decimal" type-name="NUMBER"
    size="1"/>
    <column name="MOBILNR" type="varchar" type-name="VARCHAR2"
    size="25"/>
    <column name="ORT" type="varchar" type-name="VARCHAR2"
    size="30"/>
    <column name="PERSONID" type="decimal" type-name="NUMBER"
    not-null="true" size="10"/>
    <column name="PLZ" type="varchar" type-name="VARCHAR2"
    size="5"/>
    <column name="POSTADRESSE" type="decimal" type-name="NUMBER"
    size="1"/>
    <column name="POSTFACH" type="varchar" type-name="VARCHAR2"
    size="10"/>
    <column name="STRASSE" type="varchar" type-name="VARCHAR2"
    size="30"/>
    <column name="TELEFONNR" type="varchar" type-name="VARCHAR2"
    size="25"/>
    <fk name="ADRESSE_PS" delete-action="cascade"
    to-table="VAMP.PERSON">
    <join column="MANDANTID" to-column="MANDANTID"/>
    <join column="PERSONID" to-column="ID"/>
    </fk>
    <index name="ADRESSE_ORT">
    <on column="MANDANTID"/>
    <on column="ORT"/>
    </index>
    <index name="ADRESSE_PLZ">
    <on column="MANDANTID"/>
    <on column="PLZ"/>
    </index>
    <index name="ADRESSE_PS">
    <on column="MANDANTID"/>
    <on column="PERSONID"/>
    </index>
    <index name="ADRESSE_STR">
    <on column="MANDANTID"/>
    <on column="STRASSE"/>
    </index>
    </table>
    The foreign key "ADRESSE_PS" was identified correctly.
    I've taken a look at the class OracleDictionary and it seems that the
    object "ForeignKey" considers only one column from the foreign keys -
    but I use foreign keys that include two columns ("MANDANTID", "PERSONID").
    Is that right or are foreign keys with two columns allowed by the
    OracleDictionary?
    Marc Prud'hommeaux wrote:
    Jan-
    That is odd ... Kodo should be identifying the foreign keys and ordering
    the statements accordingly. The mappings appear correct to me at first
    glance. If you run the "schemagen" tool, does Kodo correctly identify
    the foreign key constraints in the database? Can you post the output
    from the command so we can take a look?
    Jan-Esdert Franken wrote:
    Hi,
    i have problems with non-deferred foreing key constraints:
    I have a table "PERSON" and a table "ADRESSE" which has a foreign key
    to "PERSON". Both tables have primary keys with two columns.
    In the mappings I use application identity. The mappings are generated by
    xdoclet.
    We cannot use deferred constraint because we have to support following
    databases: Oracle, Firebird, MS SQL, DB2.
    I tested the mappings with Oracle and Firebird and got this exception
    (with SQL Trace):
    5602 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (1 errors)>
    [15 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
    EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
    POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
    ?, ?, ?, ?, ?, ?) [params=(int) 1, (String) [email protected], (String)
    04941 183742, (int) 12761, (int) 1, (int) 1, (String) 0171 2846751,
    (String) Oldenburg, (int) 12760, (String) 26129, (int) 1, (null) null,
    (String) Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=0]
    5602 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
    [0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
    EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
    POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
    ?, ?, ?, ?, ?, ?) [params=(int) 3, (null) null, (null) null, (int) 12764,
    (int) 1, (int) 0, (null) null, (String) Sylt, (int) 12759, (String) 25980,
    (int) 0, (null) null, (String) Stephanstra__e 47, (String) 04651 19283]
    [reused=1]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
    [0 ms] executing prepstmnt 13390902 INSERT INTO VAMP.PERSON (ANREDEID, ID,
    KUNDENNR, LOESCHBEMERKUNG, MANDANTID, NAME1, NAME2, PERSONENDATUM,
    PERSONENORT, TYP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(null)
    null, (int) 12759, (String) 9999452800, (null) null, (int) 1, (String)
    Horstmann, (String) Manfred, (Timestamp) 1959-03-10 00:00:00.381, (String)
    Flensburg, (int) 1] [reused=0]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (2 errors)>
    [0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
    EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
    POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
    ?, ?, ?, ?, ?, ?) [params=(int) 1, (String) [email protected], (String)
    04941 183742, (int) 12763, (int) 1, (int) 1, (String) 0171 2846751,
    (String) Oldenburg, (int) 12759, (String) 26129, (int) 1, (null) null,
    (String) Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=2]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
    [0 ms] executing prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART,
    EMAIL, FAXNR, ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ,
    POSTADRESSE, POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
    ?, ?, ?, ?, ?, ?) [params=(int) 3, (null) null, (null) null, (int) 12762,
    (int) 1, (int) 0, (null) null, (String) Sylt, (int) 12760, (String) 25980,
    (int) 0, (null) null, (String) Stephanstra__e 47, (String) 04651 19283]
    [reused=3]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
    [0 ms] executing prepstmnt 13390902 INSERT INTO VAMP.PERSON (ANREDEID, ID,
    KUNDENNR, LOESCHBEMERKUNG, MANDANTID, NAME1, NAME2, PERSONENDATUM,
    PERSONENORT, TYP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(null)
    null, (int) 12760, (String) 9999452801, (null) null, (int) 1, (String)
    Horstmann, (String) Christine, (Timestamp) 1972-03-10 00:00:00.381,
    (String) Erfurt, (int) 1] [reused=1]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
    [0 ms] executing prepstmnt 11320634 INSERT INTO VAMP.NATPERSON
    (ANZAHLKINDER, ARBEITGEBERID, BEITRAGSSATZ, BERUFID, BRANCHEID,
    FAMILIENSTAND, FAMSTANDSEIT, FINANZAMTID, GEBIETSFREMDERAWG, GUETERSTAND,
    IDBEHOERDE, IDNR, KIRCHENSTEUER, KVID, MANDANTID, PERSONID, PRIVATKV,
    STAAT, STEUERBERATERID, STEUERKLASSE, STEUERNR, STEUERTARIF, TITEL) VALUES
    [params=(int) 0, (null) null, (double) 0.0, (null) null, (int) 12410,
    (int) 2, (Timestamp) 1991-12-12 00:00:00.381, (null) null, (int) 0, (int)
    3, (null) null, (null) null, (int) 0, (int) 12576, (int) 1, (int) 12760,
    (int) 0, (null) null, (null) null, (int) 0, (null) null, (int) 1, (null)
    null] [reused=0]
    5618 TRACE [main] kodo.jdbc.SQL - <t 26577913, conn 33108879 (3 errors)>
    [0 ms] executing prepstmnt 11320634 INSERT INTO VAMP.NATPERSON
    (ANZAHLKINDER, ARBEITGEBERID, BEITRAGSSATZ, BERUFID, BRANCHEID,
    FAMILIENSTAND, FAMSTANDSEIT, FINANZAMTID, GEBIETSFREMDERAWG, GUETERSTAND,
    IDBEHOERDE, IDNR, KIRCHENSTEUER, KVID, MANDANTID, PERSONID, PRIVATKV,
    STAAT, STEUERBERATERID, STEUERKLASSE, STEUERNR, STEUERTARIF, TITEL) VALUES
    [params=(int) 0, (null) null, (double) 0.0, (int) 12362, (int) 12378,
    (int) 2, (Timestamp) 1991-12-12 00:00:00.381, (null) null, (int) 0, (int)
    3, (null) null, (null) null, (int) 0, (int) 12576, (int) 1, (int) 12759,
    (int) 0, (null) null, (null) null, (int) 0, (null) null, (int) 1, (null)
    null] [reused=1]
    5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
    errors)> [16 ms] rollback
    5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
    errors)> return
    5634 TRACE [main] kodo.jdbc.JDBC - <t 26577913, conn 33108879 (3
    errors)> [0 ms] close
    com.solarmetric.jdbc.ReportingSQLException: ORA-02291: integrity
    constraint (VAMP.ADRESSE_PS) violated - parent key not found
    {prepstmnt 22511833 INSERT INTO VAMP.ADRESSE (ADRESSART, EMAIL, FAXNR,
    ID, MANDANTID, MELDEADRESSE, MOBILNR, ORT, PERSONID, PLZ, POSTADRESSE,
    POSTFACH, STRASSE, TELEFONNR) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
    ?, ?) [params=(int) 1, (String) [email protected], (String) 04941
    183742, (int) 12761, (int) 1, (int) 1, (String) 0171 2846751, (String)
    Oldenburg, (int) 12760, (String) 26129, (int) 1, (null) null, (String)
    Ammerl__nder Heerstra__e 19, (String) 04941 183740] [reused=0]} [code=2291,
    state=23000]
         at
    com.solarmetric.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:124)
         at
    com.solarmetric.jdbc.LoggingConnectionDecorator.access$600(LoggingConnectionDecorator.java:19)
         at
    com.solarmetric.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:728)
         at
    com.solarmetric.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:362)
    How can I force it to insert in the table "NATPERSON" first and then in
    the table "ADRESSE"?
    I use following JDBC-drivers:
    Firebird: 1.5.5
    Oracle: 9.2.0.1.0
    My property file:
    <!-- standard properties for all dbms -->
    <prop key="kodo.LicenseKey">LICENSE KEY REMOVED</prop>
    <prop key="kodo.ConnectionFactoryProperties">MaxCachedStatements=150,
    MaxActive=50, MaxIdle=50</prop>
    <prop key="kodo.FetchBatchSize">200</prop>
    <prop key="kodo.DataCache">true(CacheSize=5000)</prop>
    <prop key="kodo.RemoteCommitProvider">sjvm</prop>
    <prop key="kodo.jdbc.MappingFactory">metadata</prop>
    <prop key="kodo.jdbc.ForeignKeyConstraints">true</prop>
    <prop key="kodo.jdbc.SchemaFactory">native</prop>
    <prop
    key="javax.jdo.PersistenceManagerFactoryClass">kodo.jdbc.runtime.JDBCPersistenceManagerFactory</prop>
    <prop key="javax.jdo.option.Optimistic">true</prop>
    <!-- oracle connection properties -->
    <prop key="kodo.jdbc.DBDictionary">oracle</prop>
    <prop
    key="javax.jdo.option.ConnectionDriverName">oracle.jdbc.driver.OracleDriver</prop>
    <prop key="javax.jdo.option.ConnectionURL">..</prop>
    <prop key="javax.jdo.option.ConnectionUserName">..</prop>
    <prop key="javax.jdo.option.ConnectionPassword">..</prop>
    <prop key="kodo.jdbc.SequenceFactory">native</prop>
    <prop key="kodo.jdbc.Schemas">..</prop>
    <!-- firebird connection properties
    <prop key="kodo.jdbc.DBDictionary">kodo.jdbc.sql.FirebirdDictionary</prop>
    <prop
    key="javax.jdo.option.ConnectionDriverName">org.firebirdsql.jdbc.FBDriver</prop>
    <prop key="javax.jdo.option.ConnectionURL">..</prop>
    <prop key="javax.jdo.option.ConnectionUserName">..</prop>
    <prop key="javax.jdo.option.ConnectionPassword">..</prop>
    <prop key="kodo.jdbc.SequenceFactory">native(TableName=SYSDUAL,
    Format="SELECT GEN_ID(,1) FROM ")</prop>
    -->
    My database schema looks like this:
    TABLE PERSON
    FIELD MANDANTID (SMALLINT REQUIRED COMMENT (""))
    FIELD ID (AUTOINC COMMENT (""))
    FIELD TYP (SMALLINT REQUIRED COMMENT (""))
    FIELD KUNDENNR (CHAR(15) COMMENT ("Kundennummer"))
    PRIMARY KEY
    FIELD MANDANTID
    FIELD ID
    FOREIGN KEY MD
    TABLE MANDANT
    FIELD MANDANTID
    INDEX KDNR
    FIELD MANDANTID
    FIELD KUNDENNR
    UNIQUE
    TABLE ADRESSE
    FIELD MANDANTID (SMALLINT REQUIRED COMMENT (""))
    FIELD ID (AUTOINC COMMENT (""))
    FIELD PERSONID (LONGINT REQUIRED COMMENT (""))
    PRIMARY KEY
    FIELD MANDANTID
    FIELD ID
    FOREIGN KEY PS
    TABLE PERSON
    FIELD MANDANTID
    FIELD PERSONID
    My metadata looks like this:
    <class name="PersonDO"
    identity-type="application"
    objectid-class="com.elaxy.vamp.dom.person.PersonDOId"
    persistence-capable-superclass="com.elaxy.vamp.dom.AbstractDO">
    <extension vendor-name="kodo"
    key="jdbc-class-ind"
    value="metadata-value">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-class-ind/column"
    value="TYP">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-class-ind-value"
    value="-1">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-class-map"
    value="base">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-class-map/table"
    value="PERSON">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map"
    value="value">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map/column"
    value="ID">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map"
    value="value">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map/column"
    value="MANDANTID">
    </extension>
    <field name="kundenNr"
    persistence-modifier="persistent">
    </field>
    <field name="adressen"
    persistence-modifier="persistent">
    <collection
    element-type="com.elaxy.vamp.dom.person.AdresseDO">
    </collection>
    <extension vendor-name="kodo"
    key="jdbc-field-map"
    value="one-many">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-map/ref-column.MANDANTID"
    value="MANDANTID">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-map/ref-column.ID"
    value="PERSONID">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-map/table"
    value="ADRESSE">
    </extension>
    </field>
    .. fields ..
    </class>
    <class name="AdresseDO"
    identity-type="application"
    objectid-class="com.elaxy.vamp.dom.person.AdresseDOId"
    persistence-capable-superclass="com.elaxy.vamp.dom.AbstractDO">
    <extension vendor-name="kodo"
    key="jdbc-class-map"
    value="base">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-class-map/table"
    value="ADRESSE">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-sequence-name"
    value="ADRESSE_SEQ">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map"
    value="value">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.id/jdbc-field-map/column"
    value="ID">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId"
    value="">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map"
    value="value">
    </extension>
    <extension vendor-name="kodo"
    key="jdbc-field-mappings/AbstractDO.mandantId/jdbc-field-map/column"
    value="MANDANTID">
    </extension>
    .. fields ..
    </class>
    Many thanks,
    Jan
    Marc Prud'hommeaux
    SolarMetric Inc.

Maybe you are looking for

  • Mac Mini Fusion Drive or self built SSD / Fusion drive

    Hi, I am contemplating to buy a Mac Mini i7 2.6GHz but don't really know what I want to do with the Harddrive. One option would of course be to add a Fusion Drive for 200 bucks. However, apple doesn't say anything about the brand or model that they u

  • How can i downgrade to my iOS 6? I dont like iOS7.

    Hello people, I have a iPhone 4S, I've recently upgrade to iOS7...OMG what i've i done !! I dont like it at all... the calendar and notes are pretty useless now, everything turned white, even the date cursor on "starts" option (date/hour) its hard to

  • Why can't I see my Apple TV menu on the HDTV screen?

    I just bought the Apple TV and, following the setup guide, connected it to my HDTV.  I have my IMAC in the same room and I am using a wireless network.  I thought that the Apple TV menu would appear on the TV screen, prompting me through a series of

  • Budget carry forward- giong up in the fund center hierarchy

    Hi, We are about to close year 2008 in the FM. We work with the former budget, and we don't have budget structure. When carry forward the commitment u2013 the receiver is the same as the sender. But, when I carry forward budget for commitment, the re

  • Flas player 11 installed but not working

    the adobe flash player 11 was just installed but i can not use it for games or videos what can i do?