I have two (2) issues I am trying to solve with regard to M:N relationships.
One on load and one on creating. I am using Castor 1.0.5 with MySQL 5.
I have an inheritance model that has an employee and customer class that extend
a Person class. I also have a bi-directional M:N relationship from Person to
Address. The relavant mapping is below.
When I read in my Employee or Customer objects, I get an infinite loop unless I
remove the "persons" field from Address (i.e. make the relationship
unidirectional). If I do this, the load of a customer or employee with its
associated set of addresses works fine.
My second issue is that the join relationship table (a person_address table) is
not getting populated when I create a Customer and Address and relate one to
the other. I have read a couple of the emails in this archive and found
suggestions for alternate creation of the objects (create and save the objects
first, set the association and then commit) but no matter what I do, the
relationship does not get saved in the database - even though the objects do.
Thanks for any help.
jim
<class name="com.intertech.domain.Person" identity="id"
key-generator="IDENTITY">
<description>Person superclass</description>
<map-to table="persons"/>
<field name="id">
<sql name="person_id" />
</field>
<!-- more fields here ... -->
<field name="addresses" type="com.intertech.domain.Address"
collection="set">
<sql name="address_id"
many-table="person_address" many-key="person_id" />
</field>
</class>
<class name="com.intertech.domain.Employee"
extends="com.intertech.domain.Person" identity="id">
<description>Employee subclass extends person</description>
<map-to table="employees" />
<field name="id">
<sql name="employee_id" />
</field>
<!-- more fields here ... -->
</class>
<class name="com.intertech.domain.Customer"
extends="com.intertech.domain.Person" identity="id">
<description>Customer subclass extends person</description>
<map-to table="customers" />
<field name="id">
<sql name="customer_id" />
</field>
<!-- more fields here ... -->
</class>
<class name="com.intertech.domain.Address" identity="id">
<description>Addresses in many to many relationship with
Person</description>
<map-to table="addresses"/>
<field name="id">
<sql name="address_id" />
</field>
<!-- more fields here ... -->
<!-- I have to remove this next field in order to avoid an infinite loop when I
read employee or customer objects -->
<field name="persons" type="com.intertech.domain.Person"
collection="set" >
<sql name="person_id"
many-table="person_address" many-key="address_id" />
</field>
</class>