Here is my mapping:
<class name="com.xyz.ObjectOne" identity="oneId"
key-generator="SEQUENCE">
<description>"First of Many-to-Many Object"</description>
<map-to table="object_one"/>
<cache-type type="none"/>
<field name="oneId" type="integer">
<sql name="object_one_id" type="integer"/>
</field>
...
<field name="objectTwo" type="com.xyz.ObjectTwo"
collection="arraylist">
<sql name="object_two_id" many-table="objectone_objecttwo_map"
many-key="object_one_id" key-generator="SEQUENCE" />
</field>
</class>
<class name="com.xyz.ObjectTwo" identity="twoId"
key-generator="SEQUENCE">
<description>"Second of Many-to-Many Object"</description>
<map-to table="object_two"/>
<cache-type type="none"/>
<field name="twoId" type="integer">
<sql name="object_two_id" type="integer"/>
</field>
...
</class>
I didn't include a reverse mapping from the ObjectTwo -> ObjectOne because I
don't have/need a property on the com.xyz.ObjectTwo class to get back to
ObjectOne.
The mapping table objectone_objecttwo_map has three relevant fields:
primary key of the mapping table itself
foreign key of 'object_one' record this is associated with
foreign key of 'object_two' record this is associated with
-Ron
-----Original Message-----
From: Werner Guttmann [mailto:[EMAIL PROTECTED]
Sent: Monday, May 02, 2005 8:12 AM
To: [email protected]
Subject: AW: [castor-dev] many-to-many mapping..
Ronald,
there's no need to define a mapping object, as your many-to-may relation
will be handled automatically by Castor. And this should by definition
include the handling of the keys in the mapping table. It looks like you
have got the mapping slightly wrong, so can you please post the relevant
mapping section, the DDL used to create the tables in question and some
information about the classes engaging in such mapping ?
Werner
-----Urspr�ngliche Nachricht-----
Von: Ronald Rudy [mailto:[EMAIL PROTECTED]
Gesendet: Montag, 02. Mai 2005 14:08
An: [email protected]
Betreff: [castor-dev] many-to-many mapping..
I have configured Castor to support a many-to-many relationship between two
types of objects, but I'm getting an error. This is because the mapping
table itself (in Oracle) contains a primary key of its own, and this is not
automatically assigned by Castor. So when a new relationship is created,
this primary key is null and the database throws an error.
I don't have control over the database schema - is there any way to
configure Castor to recognize that the configured many-table has a primary
key and the key can be created using the sequence key generator? (the
sequence key generator works fine for everything else) Or am I going to be
forced to create a "map" object that handles the relationship 'manually'?
-Ron