AW: [Objectbridge-developers] Sample Many-to-Many Mapping XML
Brought to you by:
thma
From: Mahler T. <tho...@it...> - 2001-05-29 08:07:04
|
Hi Sasha, hi all, > -----Urspr=FCngliche Nachricht----- > Von: Sasha Haghani [mailto:sha...@br...] > Gesendet: Dienstag, 29. Mai 2001 01:21 > An: 'obj...@li...' > Betreff: [Objectbridge-developers] Sample Many-to-Many Mapping XML >=20 >=20 > Hi Thomas et al, >=20 > I have a question about how to implement a M-M relationship=20 > 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=20 > single ID and > reference field for both User and Role respectively. >=20 > Can someone verify that this mapping is correct. Is there anyway to > simplify it further? Is a UserRoleRelationship object=20 > absolutely necessary? Right now this is exactly the thing you have to do! You need three = tables to decompose m-n into two 1-n relationships. Thus you also need three = classes. This approach is also suggested by the gurus: see ftp://members.aol.com/kgb1001001/Chasms/chasms.pdf. As there have been requests to have a standard mapping for m-n = relationships I'm thinking of having some support for m-n in OJB at some later point = in time ... > Note that I've defined both the userid and roleid columns as=20 > primary keys > for the UserRoleRelationship (user_role table) -- is that valid? >=20 Of course the combination of userid and roleid must be unique. If you = use them as PK you don't even need a separate ID column. > Finally, are my auto.* settings configured correctly? I'd=20 > like the deletion > of a User or Role to delete the object and any corresponding > UserRoleRelationships, both *NOT* the other side of the=20 > relation (i.e.: > typical Many-to-Many behaviour). Retrieving any object=20 > should retrieve any > dependent object (User gets related UserRoleRelationships and=20 > Roles, etc.). >=20 > Any help on this or any alternative mapping samples are much=20 > appreciated. > Thanks. The mapping sample XML is below... >=20 > Sasha Haghani > Toronto, Canada. >=20 > <ClassDescriptor id=3D"1"> > <class.name>User</class.name> > <table.name>user</table.name> > <FieldDescriptor id=3D"1"> > <field.name>userid</field.name> > <column.name>userid</column.name> > <jdbc_type>CHAR</jdbc_type> > <PrimaryKey>true</PrimaryKey> > </FieldDescriptor> > <FieldDescriptor id=3D"2"> > <field.name>username</field.name> > <column.name>username</column.name> > <jdbc_type>CHAR</jdbc_type> > </FieldDescriptor> > <CollectionDescriptor id=3D"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> >=20 > <ClassDescriptor id=3D"2"> > <class.name>UserRoleRelationship</class.name> > <table.name>user_role</table.name> > <FieldDescriptor id=3D"1"> > <field.name>userid</field.name> > <column.name>userid</column.name> > <jdbc_type>CHAR</jdbc_type> > <PrimaryKey>true</PrimaryKey> > </FieldDescriptor> > <FieldDescriptor id=3D"2"> > <field.name>roleid</field.name> > <column.name>roleid</column.name> > <jdbc_type>CHAR</jdbc_type> > <PrimaryKey>true</PrimaryKey> > </FieldDescriptor> > <ReferenceDescriptor id=3D"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=3D"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> >=20 > <ClassDescriptor id=3D"3"> > <class.name>Role</class.name> > <table.name>role</table.name> > <FieldDescriptor id=3D"1"> > <field.name>roleid</field.name> > <column.name>roleid</column.name> > <jdbc_type>CHAR</jdbc_type> > <PrimaryKey>true</PrimaryKey> > </FieldDescriptor> > <FieldDescriptor id=3D"2"> > <field.name>rolename</field.name> > <column.name>rolename</column.name> > <jdbc_type>CHAR</jdbc_type> > </FieldDescriptor> > <CollectionDescriptor id=3D"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>=09 >=20 Yes this looks good! If a user is deleted all dependent = UserRoleRelationship entries are deleted, but role entries are not touched, as the = auto.update and auto.delete flags are set to false! Sasha, I have a question: could you send me the sources for classes = User, Role and UserRoleRelationship? Until now I have no sample for a m-n mapping and would like to include something simple into our test package for demonstration of mapping techniques. thanks, Thomas > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > http://lists.sourceforge.net/lists/listinfo/objectbridge-developers >=20 |