I have another issue.
I have a Person object.
This object has a reference to an Organization object.
descriptors:

<class-descriptor class="org.jlab.mis.apps.mics.valueobjects.Person" 
table="users">
   <field-descriptor name="id" column="user_id" jdbc-type="BIGINT" primarykey="true" 
autoincrement="true" sequence-name="user_seq"/>
   <field-descriptor name="firstName" column="firstname" jdbc-type="VARCHAR" />
   <field-descriptor name="lastName" column="lastname" jdbc-type="VARCHAR" />
   <field-descriptor name="organizationId" column="organization_id" 
jdbc-type="BIGINT" />
   <reference-descriptor name="personsOrganization" 
class-ref="org.jlab.mis.apps.mics.valueobjects.Organization" auto-update="object">
     <foreignkey field-ref="organizationId" />
   </reference-descriptor>
 </class-descriptor>

 <class-descriptor class="org.jlab.mis.apps.mics.valueobjects.Organization" 
table="organizations">
   <field-descriptor name="id" column="organization_id" jdbc-type="BIGINT" primarykey="true" 
autoincrement="true" sequence-name="organization_seq"/>
   <field-descriptor name="name" column="organization_name" 
jdbc-type="VARCHAR"/>
 </class-descriptor>

Here is my code for adding a Person:

public void addPerson(Person person) throws DatasourceException{
   PersistenceBroker broker = null;
   try {
       broker = PersistenceBrokerFactory.defaultPersistenceBroker();
       broker.beginTransaction();
       broker.store(person);
       broker.commitTransaction();
   }
   catch(Exception ex){
       if(broker != null) broker.abortTransaction();
       throw new DatasourceException("Could not add person", ex);
   }
   finally{
       if (broker != null) broker.close();
   }
 }


My question is this:
1) Upon an insert of a Person, the PersistenceBroker inserts an Organization first because of the auto-update="object" attribute.
I have set up FK constraints on the DB. When the primary key is not set in the object, the PB uses the SequenceManagerNextValImpl to get the next value of the primary key.
When the broker tries to then insert the person, I get a KeyViolatedException!:


org.apache.ojb.broker.KeyConstraintViolatedException: SQL failure while insert object data for class org.jlab.mis.apps.mics.valueobjects.Person, PK of the given object is [ id=2906], object was org.jlab.mis.apps.mics.valueobjects.Person personsName='Bobby Lawrence' and organizationId='677', exception message is [ORA-02291: integrity constraint (MICS.USER_ORG_FK) violated - parent key not found.

It seems that the PersistenceBroker does not set the "organizationId" in the "users" table. The MICS.USER_ORG_FK is an Oracle contraint that checks to make sure that the Organization id exists in the Organizations table.
What am I doing wrong?


--
----------------------------
Bobby Lawrence
MIS Application Developer

Jefferson Lab (www.jlab.org)

Email: [EMAIL PROTECTED]
Office: (757) 269-5818
Pager: (757) 584-5818
----------------------------





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to