Deleting items in collection?
"Sebastian Stein" <[email protected]>
| Newsgroups | gmane.comp.jakarta.ojb.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
this might be an easy question, I'm quite new to OJB. I have a question concerning the following example:
Class A has a primary key field "PKEY" with type int and other elements in addition.
Class B has "PKEY" as a foreign key field plus another additional field. Together, both entries are the primary key for Class B.
Now, if I query Class A in source code, I want to get a Collection of objects of Class B belonging to Class A. So in repository.xml I did the following:
<class-descriptor
class="namespace.ClassA"
table="table_class_a"
>
<field-descriptor id="1"
name="pkey"
column="pkey"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
....
<collection-descriptor
name="class_b"
element-class-ref="namespace.ClassB"
auto-retrieve="true"
auto-update="true"
auto-delete="true"
orderby="pkey"
sort="DESC"
>
<inverse-foreignkey field-id-ref="1"/>
</collection-descriptor>
</class-descriptor>
And here for ClassB:
<class-descriptor
class="namespace.ClassB"
table="table_class_b"
>
<field-descriptor id="1"
name="pkey"
column="pkey"
jdbc-type="INTEGER"
primarykey="true"
/>
<field-descriptor id="2"
name="other"
column="other"
jdbc-type="VARCHAR"
primarykey="true"
/>
</class-descriptor>
Now, if I create in my source a class A instance and add a class B collection to it, everything goes fine. Class A is stored in the DB as well as all instances of class B.
On deletion of class A, I also start a query to delete all B connected to it, so something like:
broker = PersistenceBrokerFactory.createPersistenceBroker(pbkey);
Criteria crit = new Criteria();
crit.addEqualTo("pkey", new Integer(pkey));
Query query_A = new QueryByCriteria(namespace.ClassA.class, crit);
Query query_B = new QueryByCriteria(namespace.ClassB.class, crit);
broker.deleteByQuery(queryA);
broker.deleteByQuery(queryA);
If I insert a new instance of ClassB to the collection of ClassB objects in ClassA, this new instance is also automatically added to the DB. However, and now we get to the problem, if I delete an ClassB object from the collection in ClassA and store the ClassA object again, this ClassB object is not removed from the database.
What do I have to do to automatically trigger the deletion of this object?
Thanks for your help,
Sebastian
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer