Hi Stefan,

What you describe is in essence a m:n association between Address and
Person.

A Person may have multiple Adresses
An Address may have multiple Persons associated.

Apart from the tables ADDRESS and PERSON you also need an intermediary table
LINK

OJB provides out of the box support for this kind of associations. Please
have a look at:
http://db.apache.org/ojb/tutorial3.html#Mapping%20m:n%20associations


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.

I hope the tutorial3 m:n chapter will get you started.


cheers,
Thomas

> 
> 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]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to