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 Henrik Berg <he...@ifi.uio.no> on 2003/05/12 12:19:27 UTC
RemovalAwareCollection, why doesn't this work...???
Hi!
I've been staring at this for a long time now, and I just can't figure
out what I've done wrong here.
I have a class A, containing just a name (String) and a collection of
Bs (RemovalAwareCollection). The class B is just a number (int):
public class A {
private int id;
private String name;
private List elements = new RemovalAwareCollection();
//...
}
public class B {
private int id;
private int aId;
private int number;
//...
}
The repository.xml looks like this:
<class-descriptor
class="no.mb.ojbtest.A"
table="A"
>
<field-descriptor
name="id"
column="ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="name"
column="name"
jdbc-type="VARCHAR"
/>
<collection-descriptor
name="elements"
element-class-ref="no.mb.ojbtest.B"
collection-class="org.apache.ojb.broker.util.collections.RemovalAwareCollection"
auto-retrieve="true"
auto-update="true"
>
<inverse-foreignkey field-ref="aId"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor
class="no.mb.ojbtest.B"
table="B"
>
<field-descriptor
name="id"
column="ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="number"
column="number"
jdbc-type="INTEGER"
/>
<field-descriptor
name="aId"
column="aId"
jdbc-type="INTEGER"
/>
</class-descriptor>
When I do this:
A a = new A("Henrik");
B b1 = new B(4);
B b2 = new B(21);
a.add(b1);
a.add(b2);
broker.store(a);
System.out.println("Stored: " + a);
it prints (as expected)
Stored: Henrik, elements: [4, 21]
When I do this:
a.removeElement(b); // b is some element in a
broker.store(a);
System.out.println("Stored: " + a);
it prints (still as expected)
Stored: Henrik, elements: [4]
but no change at all has been made in the tables. In other words, the
removal of the element b is not persistent.
What have I done wrong?
--
Henrik
Re: RemovalAwareCollection, why doesn't this work...???
Posted by Henrik Berg <he...@ifi.uio.no>.
The frustrating thing about it is that it actually worked very well,
just a week ago or something. Then I started experimenting with it,
and messed things up quite a bit, and it stopped working. Now I've
simplified it as much as possible, but it won't work anymore...
"Edson Carlos Ericksson Richter" <ed...@mgrinformatica.com.br> writes:
> I'm gettint same problem. Is interesting that if A is related to B using
> non-decomposed M:N relation throught a AB table, it works!!!
>
> Edson Richter
>
>
> ----- Original Message -----
> From: "Henrik Berg" <he...@ifi.uio.no>
> To: <oj...@db.apache.org>
> Sent: Monday, May 12, 2003 7:19 AM
> Subject: RemovalAwareCollection, why doesn't this work...???
>
>
>
> Hi!
>
> I've been staring at this for a long time now, and I just can't figure
> out what I've done wrong here.
>
> I have a class A, containing just a name (String) and a collection of
> Bs (RemovalAwareCollection). The class B is just a number (int):
>
> public class A {
> private int id;
> private String name;
> private List elements = new RemovalAwareCollection();
> //...
> }
>
> public class B {
> private int id;
> private int aId;
> private int number;
> //...
> }
>
> The repository.xml looks like this:
>
> <class-descriptor
> class="no.mb.ojbtest.A"
> table="A"
>>
> <field-descriptor
> name="id"
> column="ID"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="true"
> />
> <field-descriptor
> name="name"
> column="name"
> jdbc-type="VARCHAR"
> />
> <collection-descriptor
> name="elements"
> element-class-ref="no.mb.ojbtest.B"
>
> collection-class="org.apache.ojb.broker.util.collections.RemovalAwareCollect
> ion"
> auto-retrieve="true"
> auto-update="true"
> >
> <inverse-foreignkey field-ref="aId"/>
> </collection-descriptor>
> </class-descriptor>
>
>
> <class-descriptor
> class="no.mb.ojbtest.B"
> table="B"
>>
> <field-descriptor
> name="id"
> column="ID"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="true"
> />
> <field-descriptor
> name="number"
> column="number"
> jdbc-type="INTEGER"
> />
> <field-descriptor
> name="aId"
> column="aId"
> jdbc-type="INTEGER"
> />
> </class-descriptor>
>
>
> When I do this:
>
> A a = new A("Henrik");
> B b1 = new B(4);
> B b2 = new B(21);
> a.add(b1);
> a.add(b2);
> broker.store(a);
>
> System.out.println("Stored: " + a);
>
> it prints (as expected)
> Stored: Henrik, elements: [4, 21]
>
> When I do this:
>
> a.removeElement(b); // b is some element in a
> broker.store(a);
> System.out.println("Stored: " + a);
>
> it prints (still as expected)
> Stored: Henrik, elements: [4]
>
> but no change at all has been made in the tables. In other words, the
> removal of the element b is not persistent.
>
> What have I done wrong?
>
> --
> Henrik
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.478 / Virus Database: 275 - Release Date: 6/5/2003
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
--
Henrik
Re: RemovalAwareCollection, why doesn't this work...???
Posted by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br>.
I'm gettint same problem. Is interesting that if A is related to B using
non-decomposed M:N relation throught a AB table, it works!!!
Edson Richter
----- Original Message -----
From: "Henrik Berg" <he...@ifi.uio.no>
To: <oj...@db.apache.org>
Sent: Monday, May 12, 2003 7:19 AM
Subject: RemovalAwareCollection, why doesn't this work...???
Hi!
I've been staring at this for a long time now, and I just can't figure
out what I've done wrong here.
I have a class A, containing just a name (String) and a collection of
Bs (RemovalAwareCollection). The class B is just a number (int):
public class A {
private int id;
private String name;
private List elements = new RemovalAwareCollection();
//...
}
public class B {
private int id;
private int aId;
private int number;
//...
}
The repository.xml looks like this:
<class-descriptor
class="no.mb.ojbtest.A"
table="A"
>
<field-descriptor
name="id"
column="ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="name"
column="name"
jdbc-type="VARCHAR"
/>
<collection-descriptor
name="elements"
element-class-ref="no.mb.ojbtest.B"
collection-class="org.apache.ojb.broker.util.collections.RemovalAwareCollect
ion"
auto-retrieve="true"
auto-update="true"
>
<inverse-foreignkey field-ref="aId"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor
class="no.mb.ojbtest.B"
table="B"
>
<field-descriptor
name="id"
column="ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="number"
column="number"
jdbc-type="INTEGER"
/>
<field-descriptor
name="aId"
column="aId"
jdbc-type="INTEGER"
/>
</class-descriptor>
When I do this:
A a = new A("Henrik");
B b1 = new B(4);
B b2 = new B(21);
a.add(b1);
a.add(b2);
broker.store(a);
System.out.println("Stored: " + a);
it prints (as expected)
Stored: Henrik, elements: [4, 21]
When I do this:
a.removeElement(b); // b is some element in a
broker.store(a);
System.out.println("Stored: " + a);
it prints (still as expected)
Stored: Henrik, elements: [4]
but no change at all has been made in the tables. In other words, the
removal of the element b is not persistent.
What have I done wrong?
--
Henrik
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.478 / Virus Database: 275 - Release Date: 6/5/2003