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 Eamonn Coleman <ea...@yahoo.com> on 2002/12/20 07:10:44 UTC

recursive m:n relationships

Hi. I'm trying to use OJB to persist objects with
recursive m:n relationships. I have both groups of
devices and groups of groups to deal with:


         parents +----+
           0..*  |    |
+------------------+  |
|       group      |  |
|------------------|--+
|                  | 0..*
|                  | children
+---------+--------+
          |0..*  
          | 
          | 
          |0..* 
+---------+--------+
|       device     |
|------------------|
|                  |
|                  |
+------------------+

Or, put in words, a group consists of zero or more
devices and a device can be in zero or more groups.
OJB handles this just fine using the "non-decomposed
m:n mappings" approach outlined in the tutorials.

A group can also contain zero or more groups and a
group can be contained by zero or more groups. This is
where I run into trouble. As far as I can tell, OJB
does not handle this kind of self-referential
many-to-many relationship as readily as it does the
group-device relationship.

I tried to coax OJB to handle the group-group
relationship in the same way it handled the
group-device relationship - using an
"indirection-table":


<class-descriptor class="device.DeviceGroup"
table="GROUP">
	<field-descriptor id="1" name="ID" column="ID"
jdbc-type="INTEGER" primarykey="true"
autoincrement="true"/>
	<field-descriptor id="2" name="name"
column="GROUP_NAME" jdbc-type="VARCHAR"/>

	<!-- group-device-->
	<collection-descriptor name="devices"
element-class-ref="device..Device"
auto-retrieve="true" auto-update="true"
indirection-table="GROUP_DEVICE">
		<fk-pointing-to-this-class column="GROUP_ID"/>
		<fk-pointing-to-element-class column="DEVICE_ID"/>
	</collection-descriptor>

	<!-- group-group -->
	<collection-descriptor name="groups"
element-class-ref="device.DeviceGroup"
auto-retrieve="true" auto-update="true"
indirection-table="GROUP_GROUP">
		<fk-pointing-to-this-class
column="PARENT_GROUP_ID"/>
		<fk-pointing-to-element-class
column="CHILD_GROUP_ID"/>
	</collection-descriptor>
</class-descriptor>


This didn't work. Further fumbling didn't yield much
either.

This topic has come up on this list before and while
it would appear that OJB should be able to handle
self-referential m:n relationships, it's not apparent
to me how to do it. The graph and tree examples only
deal with the 1:n case.

Maybe I'm missing something?

Any help would be appreciated.

eamonn



__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com