Problem: InsertQuery order changes during batch insert

From: Ingo Feulner (ing..eulner-tech.com)
Date: Wed Nov 23 2005 - 05:13:31 EST

  • Next message: Andrus Adamchik: "Re: Problem: InsertQuery order changes during batch insert"

    Hello together,

    we have the following problem here:

    We have two entities, PRODUCTS and PRODUCT_STATES.

    PRODUCTS has two relationships to PRODUCT_STATES: a to-one "currentState"
    and a to-many "historicalStates".
    PRODUCT_STATES itself has a to-one relationship to PRODUCTS.

    There are foreign-key constraints on both entities, but the one from
    PRODUCTS to PRODUCTS_STATES is deferred (we are using Oracle here).

    That means, as long as a row is inserted into PRODUCTS before the
    corresponding row is inserted into PRODUCT_STATES in one transaction all
    is going well.

    Now the problem: If we run a bigger batch of insertions into these two
    entities, there is always a point where the insertion order changes, i.e.
    PRODUCT_STATES is inserted before PRODUCTS, and that of course produces a
    constraint error by Oracle. (see log excerpt below)

    My question is now: Why does the order of inserts change and what
    influences it? How can we influence the order easily?
    It currently does not give me a good feeling, that it changes more or less
    randomly....

    Please give me a hint.. maybe there is a setting in the model that's missing.

    best regards, Ingo.

    Here is an log excerpt:

    GOOD case:

    22 Nov 2005 15:46:20,840 [Thread-6] INFO - --- transaction started.
    22 Nov 2005 15:46:20,840 [Thread-6] INFO - --- will run 20 queries.
    22 Nov 2005 15:46:20,840 [Thread-6] INFO - INSERT INTO ENTW.PARTNER (....)
    22 Nov 2005 15:46:20,840 [Thread-6] DEBUG - batch count: -2
    22 Nov 2005 15:46:20,840 [Thread-6] INFO - === updated 1 row.
    22 Nov 2005 15:46:20,840 [Thread-6] INFO - INSERT INTO ENTW.ADDRESSES (....)
    22 Nov 2005 15:46:20,856 [Thread-6] DEBUG - batch count: -2
    22 Nov 2005 15:46:20,856 [Thread-6] INFO - === updated 1 row.
    22 Nov 2005 15:46:20,856 [Thread-6] INFO - INSERT INTO ENTW.PRODUCTS (...)
    22 Nov 2005 15:46:20,856 [Thread-6] DEBUG - batch count: -2
    22 Nov 2005 15:46:20,856 [Thread-6] INFO - === updated 1 row.
    22 Nov 2005 15:46:20,856 [Thread-6] INFO - INSERT INTO
    ENTW.PRODUCT_STATES ( ....)
    22 Nov 2005 15:46:20,856 [Thread-6] INFO - === updated 1 row.

    ERROR case (same code, same run, just a few entries later)

    22 Nov 2005 15:46:20,950 [Thread-6] INFO - --- will run 20 queries.
    22 Nov 2005 15:46:20,950 [Thread-6] INFO - INSERT INTO ENTW.PARTNER (...)
    22 Nov 2005 15:46:20,950 [Thread-6] DEBUG - batch count: -2
    22 Nov 2005 15:46:20,950 [Thread-6] INFO - === updated 1 row.
    22 Nov 2005 15:46:20,950 [Thread-6] INFO - INSERT INTO ENTW.ADDRESSES (...)
    22 Nov 2005 15:46:20,950 [Thread-6] DEBUG - batch count: -2
    22 Nov 2005 15:46:20,965 [Thread-6] INFO - === updated 1 row.
    22 Nov 2005 15:46:20,965 [Thread-6] INFO - INSERT INTO
    ENTW.PRODUCT_STATES(...)
    22 Nov 2005 15:46:20,997 [Thread-6] INFO - *** error.
    java.sql.SQLException: ORA-02291: integrity constraint (ENTW.PRST_PROD_FK)
    violated - parent key not found



    This archive was generated by hypermail 2.0.0 : Wed Nov 23 2005 - 05:13:36 EST