-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: integrity constraint violation
PostPosted: Sat Feb 07, 2004 1:50 am 
Newbie

Joined: Tue Jan 13, 2004 12:13 pm
Posts: 8
Location: USA
I am getting a foreign key violation when I save an object with persistent collection. Here's all the things I have tried ...

1. Turn cascade="save-update" and invoke session.saveOrUpdate(obj) once for the entire graph
2. Remove cascade="save-update" and invoke session.saveOrUpdate(obj) for each object in the graph

Looking at the logs, it is trying to insert the collection first irrespective of the order of the save.

Env: hibernate 2.1.2, jdk 1.4.1_01, oracle 9.2, tomcat 4.1.27, win2000


================================================ Hibernate Mapping =====================================================
Code:
<hibernate-mapping package="com.agilix.iprotlims.run">

    <class name="Run">

        <id name="id" column="run_id">
            <generator class="seqhilo">
               <param name="sequence">run_id_seq</param>
               <param name="max_lo">10</param>
            </generator>
        </id>

        <version name="version" />
       
   <property name="runTypeId" column="run_type_id" />

        <many-to-one name="experiment" class="com.agilix.iprotlims.admin.Experiment" column="experiment_id" />

    </class>

    <class name="MsRun" table="ms_run">
   
        <id name="id" column="run_id">
            <generator class="assigned"> <!-- assigned from requestedRun.id -->
            </generator>
        </id>

        <version name="version" />
       
       <property name="ionSourceTypeId" column="ion_source_type_id" />

       <one-to-one name="requestedRun" class="Run" constrained="true" cascade="save-update" />

       <joined-subclass name="MaldiRun" table="maldi_ms_run">

           <key column="run_id" />
           
           <many-to-one name="plate" class="com.agilix.iprotlims.inventory.MaldiPlate" column="plate_id" />
           
           <set name="spots" lazy="true" inverse="true" cascade="save-update">
                 <key column="run_id" />
               <one-to-many class="MaldiSpot" />
           </set>

       </joined-subclass>

    </class>
   
    <query name="getOpenMsRunsByExp">
       from Run run where run.experiment = :experiment and run.startDate is null
       order by run
    </query>
   
</hibernate-mapping>

<hibernate-mapping package="com.agilix.iprotlims.run">

    <class name="MaldiSpot" table="maldi_spot">

        <id name="id" column="spot_id">
            <generator class="seqhilo">
               <param name="sequence">spot_id_seq</param>
               <param name="max_lo">10</param>
            </generator>
        </id>

   <property name="spotNumber" column="spot_num" />

   <many-to-one name="maldiRun" class="com.agilix.iprotlims.run.MaldiRun" column="run_id" />
   <many-to-one name="templateSpot" class="com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot" column="plate_template_spot_id" />

       <set name="spotSamples" lazy="true" inverse="true" cascade="save-update">
           <key column="spot_id" />
            <one-to-many class="SpotSample" />
       </set>

    </class>

</hibernate-mapping>

<hibernate-mapping package="com.agilix.iprotlims.run">

    <class name="SpotSample" table="maldi_spot_sample">

        <id name="id" column="spot_sample_id">
            <generator class="seqhilo">
               <param name="sequence">spot_sample_id_seq</param>
               <param name="max_lo">10</param>
            </generator>
        </id>

   <many-to-one name="spot" class="MaldiSpot" column="spot_id" />
   <many-to-one name="sample" class="com.agilix.iprotlims.inventory.Sample" column="sample_id" />

    </class>

</hibernate-mapping>

================================================ Test Class =====================================================
Code:
public class RunPsTest extends IProtTestCase
{
    private HibernateService _hs;
    private RunPs _ps;
    private InventoryPs _ips;
   
    {
        HibernateServiceImpl hs = new HibernateServiceImpl();
       
        hs.setThreadLocalStorage(new ThreadLocalStorageImpl());
        hs.initializeService();
        _hs = hs;

        RunHbn ps = new RunHbn();
        ps.setPersistenceService(hs);
        _ps = ps;

        InventoryHbn ips = new InventoryHbn();
        ips.setPersistenceService(hs);
        _ips = ips;
    }
   
    public RunPsTest(String arg0)
    {
        super(arg0);
    }
   
    public void setUp()
    {
        _hs.openSession();
    }

    public void tearDown()
    {
        _hs.closeSession();
    }

    public void testSaveMaldiRun()
    {
        Run run = (Run) _hs.load(Run.class, new Long(155));
       
        MaldiRun mrun = new MaldiRun(run);
       
        MaldiPlate plate = _ips.getMaldiPlate(new Long(2));
       
        MaldiSpot spot = new MaldiSpot();
        spot.setMaldiRun(mrun);
       
        MaldiPlateTemplateSpot tspot = (MaldiPlateTemplateSpot) plate.getTemplate().getSpots().iterator().next();

        spot.setSpotNumber(tspot.getSpotNumber());
        spot.setTemplateSpot(tspot);
       
        mrun.addSpot(spot);
       
        try
        {
            _hs.startTransaction();
            _ps.saveMaldiRun(mrun);
        }
        catch (Exception e)
        {
            _hs.rollbackTransaction();
            throw new AssertionFailedError("saveMaldiRun() failed ...");
        }
        finally
        {
            _hs.commitTransaction();
        }
    }
}

============================================================= Hibernate Log ==========================================================
00:18:01,286 DEBUG JDBCTransaction:37 - begin
00:18:01,286 DEBUG JDBCTransaction:41 - current autocommit status:false
00:18:01,286 DEBUG SessionImpl:1343 - saveOrUpdate() persistent instance
00:18:01,286 DEBUG Cascades:396 - version unsaved-value strategy UNDEFINED
00:18:01,286 DEBUG Cascades:341 - id unsaved-value strategy NULL
00:18:01,286 DEBUG SessionImpl:1363 - saveOrUpdate() previously saved instance with id: 155
00:18:01,286 DEBUG SessionImpl:1411 - updating [com.agilix.iprotlims.run.MaldiRun#155]
00:18:01,296 DEBUG SessionImpl:1258 - collection dereferenced while transient [com.agilix.iprotlims.run.MaldiRun.spots#155]
00:18:01,306 DEBUG SessionImpl:1358 - saveOrUpdate() unsaved instance
00:18:01,306 DEBUG BatcherImpl:196 - about to open: 0 open PreparedStatements, 0 open ResultSets
00:18:01,306 DEBUG SQL:237 - select spot_id_seq.nextval from dual
00:18:01,306 DEBUG BatcherImpl:241 - preparing statement
00:18:01,466 DEBUG SequenceGenerator:80 - Sequence identifier generated: 19
00:18:01,466 DEBUG BatcherImpl:203 - done closing: 0 open PreparedStatements, 0 open ResultSets
00:18:01,466 DEBUG BatcherImpl:261 - closing statement
00:18:01,506 DEBUG SequenceHiLoGenerator:57 - new hi value: 19
00:18:01,506 DEBUG SessionImpl:760 - generated identifier: 210
00:18:01,506 DEBUG SessionImpl:807 - saving [com.agilix.iprotlims.run.MaldiSpot#210]
00:18:01,506 DEBUG SessionImpl:2210 - flushing session
00:18:01,506 DEBUG SessionImpl:2403 - Flushing entities and processing referenced collections
00:18:01,516 DEBUG AbstractEntityPersister:275 - com.agilix.iprotlims.run.Run.startDate is dirty
00:18:01,516 DEBUG SessionImpl:2497 - Updating entity: [com.agilix.iprotlims.run.Run#155]
00:18:01,516 DEBUG Versioning:26 - Incrementing: 0 to 1
00:18:01,526 DEBUG SessionImpl:2850 - Collection found: [com.agilix.iprotlims.inventory.MaldiPlateTemplate.spots#2], was: [com.agilix.iprotlims.inventory.MaldiPlateTemplate.spots#2]
00:18:01,526 DEBUG WrapVisitor:76 - Wrapped collection in role: com.agilix.iprotlims.run.MaldiRun.spots
00:18:01,526 DEBUG SessionImpl:2497 - Updating entity: [com.agilix.iprotlims.run.MaldiRun#155]
00:18:01,526 DEBUG Versioning:26 - Incrementing: 0 to 1
00:18:01,526 DEBUG SessionImpl:2850 - Collection found: [com.agilix.iprotlims.run.MaldiRun.spots#155], was: [<unreferenced>]
00:18:01,526 DEBUG WrapVisitor:76 - Wrapped collection in role: com.agilix.iprotlims.run.MaldiSpot.spotSamples
00:18:01,526 DEBUG SessionImpl:2850 - Collection found: [com.agilix.iprotlims.run.MaldiSpot.spotSamples#210], was: [<unreferenced>]
00:18:01,536 DEBUG SessionImpl:2746 - Processing unreferenced collections
00:18:01,536 DEBUG SessionImpl:2760 - Scheduling collection removes/(re)creates/updates
00:18:01,536 DEBUG SessionImpl:2234 - Flushed: 1 insertions, 2 updates, 0 deletions to 134 objects
00:18:01,536 DEBUG SessionImpl:2239 - Flushed: 2 (re)creations, 0 updates, 1 removals to 3 collections
00:18:01,536 DEBUG Printer:75 - listing entities:
00:18:01,546 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=5, rowNumber=1, colNumber=5, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=405}
00:18:01,546 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=4, rowNumber=1, colNumber=4, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=404}
00:18:01,546 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=3, rowNumber=1, colNumber=3, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=403}
00:18:01,546 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=2, rowNumber=1, colNumber=2, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=402}
00:18:01,546 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=1, rowNumber=1, colNumber=1, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=401}
00:18:01,546 DEBUG Printer:82 - com.agilix.iprotlims.run.MaldiRun{id=155, ionSourceTypeId=1, durationAttr=null, plate=MaldiPlate#2, spots=[MaldiSpot#210], version=1, sampleCountAttr=null, batchFileName=null, requestedRun=Run#155, wiffFileCountAttr=null}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.run.Run{experiment=Experiment#1, id=155, operator=null, runTypeId=1, startDate=07 February 2004 00:18:01, requestor=ProjectLead#1, comments=null, version=0, createDate=04 February 2004 13:48:30, instrument=null}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=100, rowNumber=10, colNumber=10, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=500}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=99, rowNumber=10, colNumber=9, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=499}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=98, rowNumber=10, colNumber=8, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=498}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=97, rowNumber=10, colNumber=7, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=497}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=96, rowNumber=10, colNumber=6, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=496}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=95, rowNumber=10, colNumber=5, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=495}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=94, rowNumber=10, colNumber=4, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=494}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=93, rowNumber=10, colNumber=3, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=493}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=92, rowNumber=10, colNumber=2, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=492}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=91, rowNumber=10, colNumber=1, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=491}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=90, rowNumber=9, colNumber=10, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=490}
00:18:01,556 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=89, rowNumber=9, colNumber=9, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=489}
00:18:01,616 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=88, rowNumber=9, colNumber=8, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=488}
00:18:01,616 DEBUG Printer:82 - com.agilix.iprotlims.inventory.MaldiPlateTemplateSpot{spotNumber=87, rowNumber=9, colNumber=7, rowName=null, template=MaldiPlateTemplate#2, colName=null, id=487}
00:18:01,616 DEBUG Printer:79 - more......
00:18:01,616 DEBUG SessionImpl:2323 - executing flush
00:18:01,616 DEBUG EntityPersister:453 - Inserting entity: [com.agilix.iprotlims.run.MaldiSpot#210]
00:18:01,616 DEBUG BatcherImpl:196 - about to open: 0 open PreparedStatements, 0 open ResultSets
00:18:01,616 DEBUG SQL:237 - insert into maldi_spot (spot_num, run_id, plate_template_spot_id, spot_id) values (?, ?, ?, ?)
00:18:01,616 DEBUG BatcherImpl:241 - preparing statement
00:18:01,646 DEBUG EntityPersister:388 - Dehydrating entity: [com.agilix.iprotlims.run.MaldiSpot#210]
00:18:01,646 DEBUG IntegerType:46 - binding '85' to parameter: 1
00:18:01,646 DEBUG LongType:46 - binding '155' to parameter: 2
00:18:01,646 DEBUG LongType:46 - binding '485' to parameter: 3
00:18:01,656 DEBUG LongType:46 - binding '210' to parameter: 4
00:18:01,656 DEBUG BatcherImpl:28 - Adding to batch
00:18:01,656 DEBUG BatcherImpl:50 - Executing batch size: 1
00:18:01,736 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.BatchUpdateException: ORA-02291: integrity constraint (ILIMS.MALDI_SPOT_FK1) violated - parent key not found

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2385)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at com.agilix.iprotlims.psImpl.HibernateServiceImpl.commitTransaction(HibernateServiceImpl.java:133)
at junit.run.RunPsTest.testSaveMaldiRun(RunPsTest.java:121)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
00:18:01,736 WARN JDBCExceptionReporter:38 - SQL Error: 2291, SQLState: 23000
00:18:01,736 ERROR JDBCExceptionReporter:46 - ORA-02291: integrity constraint (ILIMS.MALDI_SPOT_FK1) violated - parent key not found

00:18:01,736 WARN JDBCExceptionReporter:38 - SQL Error: 2291, SQLState: 23000
00:18:01,736 ERROR JDBCExceptionReporter:46 - ORA-02291: integrity constraint (ILIMS.MALDI_SPOT_FK1) violated - parent key not found

00:18:01,736 DEBUG BatcherImpl:203 - done closing: 0 open PreparedStatements, 0 open ResultSets
00:18:01,746 DEBUG BatcherImpl:261 - closing statement
00:18:01,776 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.BatchUpdateException: ORA-02291: integrity constraint (ILIMS.MALDI_SPOT_FK1) violated - parent key not found

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2385)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at com.agilix.iprotlims.psImpl.HibernateServiceImpl.commitTransaction(HibernateServiceImpl.java:133)
at junit.run.RunPsTest.testSaveMaldiRun(RunPsTest.java:121)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
00:18:01,776 WARN JDBCExceptionReporter:38 - SQL Error: 2291, SQLState: 23000
00:18:01,776 ERROR JDBCExceptionReporter:46 - ORA-02291: integrity constraint (ILIMS.MALDI_SPOT_FK1) violated - parent key not found

00:18:01,776 WARN JDBCExceptionReporter:38 - SQL Error: 2291, SQLState: 23000
00:18:01,776 ERROR JDBCExceptionReporter:46 - ORA-02291: integrity constraint (ILIMS.MALDI_SPOT_FK1) violated - parent key not found

00:18:01,776 ERROR JDBCExceptionReporter:38 - Could not execute JDBC batch update
java.sql.BatchUpdateException: ORA-02291: integrity constraint (ILIMS.MALDI_SPOT_FK1) violated - parent key not found

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2385)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at com.agilix.iprotlims.psImpl.HibernateServiceImpl.commitTransaction(HibernateServiceImpl.java:133)
at junit.run.RunPsTest.testSaveMaldiRun(RunPsTest.java:121)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
00:18:01,786 ERROR SessionImpl:2343 - Could not synchronize database state with session
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2385)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at com.agilix.iprotlims.psImpl.HibernateServiceImpl.commitTransaction(HibernateServiceImpl.java:133)
at junit.run.RunPsTest.testSaveMaldiRun(RunPsTest.java:121)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
Caused by:
java.sql.BatchUpdateException: ORA-02291: integrity constraint (ILIMS.MALDI_SPOT_FK1) violated - parent key not found
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
... 17 more
Caused by:
java.sql.SQLException: ORA-02291: integrity constraint (ILIMS.MALDI_SPOT_FK1) violated - parent key not found
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3899)
... 19 more


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2004 2:10 am 
Newbie

Joined: Tue Jan 13, 2004 12:13 pm
Posts: 8
Location: USA
Forgot the saveMaldiRun() method, here it goes ...

This is when cascade="save-update" was turned off.

Code:
    public void saveMaldiRun(MaldiRun run)
    {
        run.setId(run.getRequestedRun().getId());
        run.setStartDate(new Date());
        run.setIonSourceTypeId(MALDI);
       
        _session.saveOrUpdate(run.getRequestedRun());
       
        _session.saveOrUpdate(run);
       
        _session.saveOrUpdate(run.getSpots());
       
        MaldiSpot spot;
        SpotSample spotSample;
       
        for (Iterator itr = run.getSpots().iterator(); itr.hasNext();)
        {
            spot = (MaldiSpot) itr.next();
           
            _session.saveOrUpdate(spot);
           
            for (Iterator sampleItr = spot.getSpotSamples().iterator(); sampleItr.hasNext();)
            {
                spotSample = (SpotSample) sampleItr.next();
               
                _session.saveOrUpdate(spotSample);
            }
        }
    }


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2004 12:16 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Try batch_size=0

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2004 1:19 pm 
Newbie

Joined: Tue Jan 13, 2004 12:13 pm
Posts: 8
Location: USA
Ok, I fixed it. The problem was invoking the session.saveOrUpdate when the id was generated.

My solution for future hunters:
Code:
<hibernate-mapping package="com.agilix.iprotlims.run">

    <class name="Run">

        <id name="id" column="run_id">
            <generator class="seqhilo">
               <param name="sequence">run_id_seq</param>
               <param name="max_lo">10</param>
            </generator>
        </id>

        <version name="version" />
       
         <property name="runTypeId" column="run_type_id" />
   </class>

    <class name="MsRun" table="ms_run">
   
        <id name="id" column="run_id">
            <generator class="foreign">
               <param name="property">requestedRun</param>
            </generator>
        </id>

        <version name="version" unsaved-value="negative" />
       
       <property name="ionSourceTypeId" column="ion_source_type_id" />

       <one-to-one name="requestedRun" class="Run" constrained="true" cascade="save-update" />

       <joined-subclass name="MaldiRun" table="maldi_ms_run">

           <key column="run_id" />
           
           <many-to-one name="plate" class="com.agilix.iprotlims.inventory.MaldiPlate" column="plate_id" />
           
           <set name="spots" lazy="true" inverse="true" cascade="save-update">
              <key column="run_id" />
               <one-to-many class="MaldiSpot" />
           </set>

       </joined-subclass>

    </class>
   
</hibernate-mapping>


Now I can simply call session.saveOrUpdate(maldiRun). Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.