> -----Original Message----- > From: Mahler Thomas > Sent: Tuesday, December 16, 2003 2:10 PM > To: 'Stefan Schl�sser' > Subject: RE: Unusual object relation mapping possible with OJB ? > > > Hi Stephan, > > > > > Hi Thomas, > > > > Sure, I need the link table. > > I read throught the examples in the link you gave before > posting, my > > problem is that I do not have and don't want to make the > relationship > > explicit on the object level. I.e. Persons or Address do NOT have a > > collection pointing to the other type. > > OK, then you can't use the non-decomposed m:n mapping > feature, but must use the explicit decomposition: > http://db.apache.org/ojb/tutorial3.html#Manual%20decomposition > %20into%20two%201:n%20associations > > > The collection descriptor > > contains an attribute name refering to field to hold the > > relation. There > > is no such example on the page. > > ??? > > > > > How do I define the relationship if no such field exists on > > the object > > level ? > > In this case you need a persistent class Link that is mapped > on the LINK table. > > > The attributes sourcetype and targettype are used so what I > can do a > > generic access to the link table - the link table can thus describe > > relationships between any kind of object. The approach > works well for > > small numbers of links since it is quite flexible. > > This is also the reason for not having a reference inside the value > > object pointing to the linked class. > > Using such a link is cool. But you will have to implemnt your > own indirection logic that maps types Id to real classes. > OJB does not provide automatic support for this. > > But OJB provides something moch more generic: > You can define a LINK table as follows: > > CREATE TABLE LINK ( > ADDRESS_OID VARCHAR NOT NULL, > PERSON_OID VARCHAR NOT NULL, > PRIMARY KEY (ADDRESS_OID, PERSON_OID) > ); > > You then define a link class that stores > org.apache.ojb.broker.Identity objects in those VARCHAR columns. > The Identities can be uses a generic "pointer" to arbitrary > persistent objects. > > Have a look at the source of > o.a.ojb.odmg.collections.DMapEntry and its class-descriptor > in the repository > to see how you can code such a map. > > cheers, > Thomas > > > > > Thanks for your help, > > > > Stefan Schl�sser > > > > > > Mahler Thomas wrote: > > > > > The only thing whcih seems to be a bit non-standard is > the usage of > > > attributes sourcetype and targettype. I don't see why such > > attributes are > > > required? > > > > > > IMO you just need a LINK table with the following DDL > > > > > > CREATE TABLE LINK ( > > > ADDRESS_ID INT NOT NULL, > > > PERSON_ID INT NOT NULL, > > > PRIMARY KEY (ADDRESS_ID, PERSON_ID) > > > ); > > > > > > You won't an Entity class, but can define the m:n in the > > > collection-descriptors fpr Address and Person. > > > > >Hi, > > >I would like to know how to describe the following > relations in the > > > repository.xml. > > > > > > class Address{ //no reference to Person > > > static long type = 1; > > > long id; > > > > > > String streetName; > > > } > > > > > > class Link{ //links Persons and address by id and type > > > long sourcetype; > > > long sourceid; > > > > > > long targettype; > > > long targetid;y > > > } > > > > > > class Person{ //no reference to Address > > > static long type = 2; > > > long id; > > > > > > String firstName; > > > } > > > > > > I know how to map the individual classes but how do I describe a > > > relationship between Addresses and Persons ? > > > The relationship is defined such that it exists if a > link with the > > > sourcetype=1, targettype=2 and the ids of the objects exists. > > > > > > I don't want to retrieve Persons when loading addresses, > > > hence no Person > > > or Address field referencing the other class exists - but be > > > able to do > > > a query to retrieve all Persons with a specific streetName. > > > > > > Is that possible with OJB ? > > > > > > If not, how do I need to change the model to make it work ? > > > > > > Also I do not wish to carry the type field in each object, > > is there a > > > way to get rid of it and specifiy it in the repository descriptor > > > directly (with the value) ? > > > > > > Is there a solution which avoids putting references of one > > class into > > > the other ? > > > > > > Thanks for any ideas. > > > > > > Stefan Schl�sser > > >
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
