I've problems with the many-to-many relation using Castor JDO. Can somebody
explain me why my assocaition table keeps empty.
In fact, here is the situation :
I want to set a many-to-many relation between 2 class : Channel and Item.
(A Channel can have 0 or more Items and an Item can belong to 0 or more
Channels)
I've tested the one-to-many relation and it works fine (each Item has a
foreign key on channel).
Here is my xml mapping file to test the many-to-many relation:
<class name="com.ibm.essonnes.castor.jdoTestSuite.rssDef.Channel"� identity
="id">
��� <description>Channel</description>
��� <cache-type type="unlimited"/>
��� <map-to table="channel" />
��� <field name="id" type="integer">
��� <sql name="id" type="integer" />
��� </field>
...
��� <field name="items" type
="com.ibm.essonnes.castor.jdoTestSuite.rssDef.Item" required="true"
collection="vector">
��� <sql name="item_id" many-table="channel_item" many-key="channel_id" />
��� </field>
</class>
<class name="com.ibm.essonnes.castor.jdoTestSuite.rssDef.Item" identity
="id" >
��� <description>Item </description>
��� <cache-type type="unlimited"/>
��� <map-to table="item" />
��� <field name="id" type="integer">
��� <sql name="id" type="integer" />
��� </field>
...
��� <field name="channels" type
="com.ibm.essonnes.castor.jdoTestSuite.rssDef.Channel" required="true"
collection="vector">
��� <sql name="channel_id" many-table="channel_item" many-key="item_id" />
��� </field>
</class>
My java Class contains:
* in Channel.java:
public void setItem(Item item) {
this.item = item;
}
public Item getItem() {
return item;
}
public void setItems(Vector items) {
this.items=items;
}
public Vector getItems() {
return items;
}
public void addItem( Item item ) {
items.addElement( item );
item.setChannel( this );
}
*In Item.java:
public Channel getChannel() {
return channel;
}
public void setChannel( Channel channel ) {
this.channel = channel;
}
public Vector getChannels() {
return channels;
}
public void setChannels(Vector channels) {
this.channels = channels;
}
public void addChannel(Channel channel) {
channels.addElement(channel);
channel.setItem(this);
}
* to test, I wrote :
...
for (int i = 1; i <= 5; i++) {
Channel channel = new Channel();
channel.setId(i);
for (int j=1;j<=10;j++) {
Item item = new Item();
item.setId(j);
item.addChannel(channel);
db.create(item);
channel.addItem(item);
}
db.create(channel);
db.commit();
}
...
My trouble is that my association table (channel_item) contains�0 values
after execution; and no errors are reported.
I hope someone of you�have an�Idea and will take some of his time to answer
me,
Thanks a lot
Coridialement/Regards
Pascal Gheeraert
PS : I work with the DB2 database.
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev