[Objectbridge-developers] Sample Many-to-Many Mapping XML
Brought to you by:
thma
From: Sasha H. <sha...@br...> - 2001-05-28 23:20:41
|
Hi Thomas et al, I have a question about how to implement a M-M relationship using OJB. I've included a sample mapping which uses three objects, User, Role & UserRoleRelationship. User and Role each have a collection of UserRoleRelationship objects. And UserRoleRelationship has a single ID and reference field for both User and Role respectively. Can someone verify that this mapping is correct. Is there anyway to simplify it further? Is a UserRoleRelationship object absolutely necessary? Note that I've defined both the userid and roleid columns as primary keys for the UserRoleRelationship (user_role table) -- is that valid? Finally, are my auto.* settings configured correctly? I'd like the deletion of a User or Role to delete the object and any corresponding UserRoleRelationships, both *NOT* the other side of the relation (i.e.: typical Many-to-Many behaviour). Retrieving any object should retrieve any dependent object (User gets related UserRoleRelationships and Roles, etc.). Any help on this or any alternative mapping samples are much appreciated. Thanks. The mapping sample XML is below... Sasha Haghani Toronto, Canada. <ClassDescriptor id="1"> <class.name>User</class.name> <table.name>user</table.name> <FieldDescriptor id="1"> <field.name>userid</field.name> <column.name>userid</column.name> <jdbc_type>CHAR</jdbc_type> <PrimaryKey>true</PrimaryKey> </FieldDescriptor> <FieldDescriptor id="2"> <field.name>username</field.name> <column.name>username</column.name> <jdbc_type>CHAR</jdbc_type> </FieldDescriptor> <CollectionDescriptor id="1"> <cdfield.name>roles</cdfield.name> <items.class>UserRoleRelationship</items.class> <descriptor_ids>1</descriptor_ids> <auto.retrieve>true</auto.retrieve> <auto.update>true</auto.update> <auto.delete>true</auto.delete> </CollectionDescriptor> </ClassDescriptor> <ClassDescriptor id="2"> <class.name>UserRoleRelationship</class.name> <table.name>user_role</table.name> <FieldDescriptor id="1"> <field.name>userid</field.name> <column.name>userid</column.name> <jdbc_type>CHAR</jdbc_type> <PrimaryKey>true</PrimaryKey> </FieldDescriptor> <FieldDescriptor id="2"> <field.name>roleid</field.name> <column.name>roleid</column.name> <jdbc_type>CHAR</jdbc_type> <PrimaryKey>true</PrimaryKey> </FieldDescriptor> <ReferenceDescriptor id="1"> <rdfield.name>user</rdfield.name> <referenced.class>User</referenced.class> <descriptor_ids>1</descriptor_ids> <auto.retrieve>true</auto.retrieve> <auto.update>false</auto.update> <auto.delete>false</auto.delete> </ReferenceDescriptor> <ReferenceDescriptor id="2"> <rdfield.name>role</rdfield.name> <referenced.class>Role</referenced.class> <descriptor_ids>2</descriptor_ids> <auto.retrieve>true</auto.retrieve> <auto.update>false</auto.update> <auto.delete>false</auto.delete> </ReferenceDescriptor> </ClassDescriptor> <ClassDescriptor id="3"> <class.name>Role</class.name> <table.name>role</table.name> <FieldDescriptor id="1"> <field.name>roleid</field.name> <column.name>roleid</column.name> <jdbc_type>CHAR</jdbc_type> <PrimaryKey>true</PrimaryKey> </FieldDescriptor> <FieldDescriptor id="2"> <field.name>rolename</field.name> <column.name>rolename</column.name> <jdbc_type>CHAR</jdbc_type> </FieldDescriptor> <CollectionDescriptor id="1"> <cdfield.name>roles</cdfield.name> <items.class>UserRoleRelationship</items.class> <descriptor_ids>2</descriptor_ids> <auto.retrieve>true</auto.retrieve> <auto.update>true</auto.update> <auto.delete>true</auto.delete> </CollectionDescriptor> </ClassDescriptor> |