I have Object A related to object B with a 1:n relation.
I want to remove an instance of A with all instance of B related to A.
What's the corret approach?
I tried this:
Mapping:
<class name="A"
identity="id" key-generator="hotelservice_seq">
<description>A</description>
<map-to table="hotelservice" xml="hotelservice" />
....
<field name="b" type="B" collection="collection">
<sql many-key="a_id"/>
</field>
</class>
<class name="B"
identity="id" key-generator="hotelservice_seq">
<description>B</description>
<map-to table="hotelservice" xml="hotelservice" />
....
<field name="a" type="A">
<sql name="a_id"/>
</field>
</class>
I tried this code:
db.begin();
A a;
Iterator iter = a.getB().iterator();
while(iter.hasNext()) {
B b = (B)iter.next();
db.remove(b);
}
db.remove(a);
db.commit();
but it doesn't work. I used latest cvs source. I tested it with 2 references
of B relatated to a reference of A. While I iterate through references of B
if I comment out db.remove(b) I get 2 references. If I leave the line in the
code I get only 1 reference. I think db.remove(b) removes the reference of B
from the Collection and bugs iterator for the next reference of B. Any
suggestion?
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev