> it looks like ojb will insert the collection records > before inserting the parent record.
hmm, there are many test cases using 1:n relations without problems. Only difference I can see is that the FK field in DusoiAssessmentVO is a PK field too (but this shouldn't have an side-effect).
Can you post the code of BasicDAO.insert?
regards, Armin
Paul He wrote:
when doing inserting a object A that has 1:n relationship with a collection of object B, I am getting this error:
java.sql.SQLException: ORA-02291: integrity constraint (SCI_DEV.DUSOI_ASSESSMENT_FK) violated - parent key not found.
at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeInsert(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.storeCollectionObject(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.storeCollections(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(Unknown Source) at gov.va.med.sci.dao.BasicDAO.insert(BasicDAO.java:65)
it looks like ojb will insert the collection records before inserting the parent record. The auto
increment sequence is generated by ojb for the parent
table's primary key (ID), which is the foreign key for
the children table. data are loaded into collection
of object B before inserting A. Do you know why it
error out?
<class-descriptor class="com.abc.PatientAssessmentsVO" table="PATIENT_ASSESSMENTS"
>>
<field-descriptor id="0"
name="id"
column="ID"
jdbc-type="BIGINT"
primarykey="true"
autoincrement="true"
sequence-name="patientassessments_id"
/>
<field-descriptor id="1"
name="integration_control_number"
column="INTEGRATION_CONTROL_NUMBER"
jdbc-type="VARCHAR"
/>
<field-descriptor id="2"
name="instrument_name"
column="INSTRUMENT_NAME"
jdbc-type="VARCHAR"
/>
<field-descriptor id="3"
name="date_recorded"
column="DATE_RECORDED"
jdbc-type="TIMESTAMP"conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimestampFieldConversion"
/>
<collection-descriptor
name="allAssementsInGroup"
collection-class="com.abc.AssessmentCollection"
element-class-ref="com.abc.DusoiAssessmentVO"
auto-retrieve="true"
auto-update="true"
auto-delete="true"
>
<inverse-foreignkey field-id-ref="3"/>
</collection-descriptor>
</class-descriptor>
and Class DusoiAssessmentVO is defined as: <class-descriptor class="com.abc.DusoiAssessmentVO" table="SCI_DEV.DUSOI_ASSESSMENT"
>>
<field-descriptor id="0"
name="integration_control_number"
column="INTEGRATION_CONTROL_NUMBER"
jdbc-type="VARCHAR"
primarykey="true"
/>
<field-descriptor id="1"
name="date_recorded"
column="DATE_RECORDED"
jdbc-type="TIMESTAMP"
primarykey="true"conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimestampFieldConversion"
/>
<field-descriptor id="2"
name="instrument_version"
column="INSTRUMENT_VERSION"
jdbc-type="BIGINT"
/>
<field-descriptor id="3"
name="patient_assessments_id"
column="PATIENT_ASSESSMENTS_ID"
primarykey="true"
jdbc-type="BIGINT"
/>
</class-descriptor>and <descriptor-repository version="1.0"
isolation-level="read-uncommitted"
proxy-prefetching-limit="50"> <!-- this connection was used as the default one
within OJB -->
<jdbc-connection-descriptor
jcd-alias="default"
default-connection="true"
platform="Oracle"
jdbc-level="2.0"
jndi-datasource-name="jdbc/pool/SCIDO_DS_Pooled"
username="xxx"
password="yyyy"
eager-release="false"
batch-mode="false"
useAutoCommit="1"
ignoreAutoCommitExceptions="false">
<connection-pool maxActive="21"
validationQuery="" />
<sequence-manager
className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
<attribute attribute-name="autoNaming"
attribute-value="false"/>
<attribute attribute-name="grabSize"
attribute-value="20"/>
</sequence-manager>
</jdbc-connection-descriptor>Thanks.
Paul
__________________________________ Do you Yahoo!? Yahoo! Photos: High-quality 4x6 digital prints for 25� http://photos.yahoo.com/ph/print_splash
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
