You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by "Hiller, Frank RD-AS2" <Fr...@heidelberg.com> on 2005/03/16 11:47:37 UTC

How to delete single objects in a referenced collection?

I'm using two classes/tables in a 1:n reference with PerstistenceBroker
API. In the first table I have the machines and in the second one the
currently logged on persons. In the EMPLOYEES table I'm using a PK of
two columns (PERSONALID / MACHINEID). I'm not using ID. When a person
logs off, it is not deleted from EMPLOYEES table when using .store(obj).
The object contains the reduced collection of employees. If the machine
is removed, then all looged on persons are removed, too. So my
workaround is first .delete(oldObj), second .store(newObj) in a
transaction.
 
I'd rather use only store(newObj). But how to get it working?
 
Class/collection descriptors look like this:
 
   <class-descriptor
      class="com.aaa.bbb.ccc.ddd.Machine"
      table="MACHINE"
   >

  // some field descriptors....
 
   <collection-descriptor
      name="employees"
      element-class-ref="com.aaa.bbb.ccc.ddd.Employee"
      auto-retrieve="true"
      auto-update="true"
      auto-delete="true"
  orderby="personalid"
  sort="ASC"
    >
  <inverse-foreignkey field-ref="deviceID" />
     </collection-descriptor>
   </class-descriptor>

 
   <class-descriptor
      class="com.aaa.bbb.ccc.ddd.Employee"
      table="EMPLOYEE"
   >
 
      <field-descriptor
         name="familyName"
         column="FAMILYNAME"
         jdbc-type="VARCHAR"
         primarykey="false"
         autoincrement="false"
      />
 
     <field-descriptor
         name="firstName"
         column="FIRSTNAME"
         jdbc-type="VARCHAR"
         primarykey="false"
         autoincrement="false"
      />
     
     <field-descriptor
         name="personalID"
         column="PERSONALID"
         jdbc-type="VARCHAR"
         primarykey="true"
         autoincrement="false"
      />
     
     <field-descriptor
         name="roles"
         column="ROLES"
         jdbc-type="VARCHAR"
         primarykey="false"
         autoincrement="false"
      />
 
     <field-descriptor
         name="deviceID"
         column="DEVICEID"
         jdbc-type="VARCHAR"
         primarykey="true"
         autoincrement="false"
      />
 
   </class-descriptor>
 
 
Cheers,
Frank
 

Re: How to delete single objects in a referenced collection?

Posted by Martin Kalén <mk...@apache.org>.
Hiller, Frank RD-AS2 wrote:
> In the first table I have the machines and in the second one the
> currently logged on persons. In the EMPLOYEES table I'm using a PK of
> two columns (PERSONALID / MACHINEID). I'm not using ID. When a person
> logs off, it is not deleted from EMPLOYEES table when using .store(obj).
> The object contains the reduced collection of employees.

In the database, is the column "EMPLOYEE.PERSONALID" a foreign key or 
reference to another table? If you a dropping people from this table the 
sequence of things in the transaction could be important.

If the removal aware collection is trying to delete EMPLOYEE when 
personalId is either 0/null or references a deleted tuple, I guess you 
will run into problems.


There is also no object-level cache consistency in the PB API, so it 
could simply be that you are reading the object back from cache when 
testing?

Use P6Spy to check what SQL statements are beeing sent to the database.

Regards,
  Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org