Re: Problem: InsertQuery order changes during batch insert

From: Ingo Feulner (ing..eulner-tech.com)
Date: Thu Nov 24 2005 - 14:10:49 EST

  • Next message: Mike Kienenberger: "Re: Dates inserted into Oracle do not have Minutes / Seconds?"

    Thanks Andrus, we will go the 2nd way. But that means to go with 1.2, as
    1.1.3 does not have setEntitySorter()...

    Regards, Ingo.

    > 2. Subclass org.objectstyle.cayenne.map.AshwoodEntitySorter,
    > overriding "sortDbEntities" to provide your own order when these two
    > entities are involved. Then configure DataNode to use your sorter -
    > DataNode.setEntitySorter(..)
    >
    > Andrus
    >
    >
    >
    >
    > On Nov 23, 2005, at 1:13 PM, Ingo Feulner wrote:
    >> 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
    >>
    >>
    >
    >
    >

    -- 
    Ingo Feulner
    Feulner Technology Solutions
    



    This archive was generated by hypermail 2.0.0 : Thu Nov 24 2005 - 14:10:52 EST