Ronald,

Castor unfortunately will require you to define the reverse leg of the 
many-to-many relation as well, even if you don't need from within your 
application. Without both legs, this will not work. And that's exactly the 
reason why you are seeing the keys not being set.

Regards
Werner

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

Reply via email to