Frage

Assuming I have two classes that are of this form

class Person {
    String name;
    List<Organization> orgs;
}

class Organization {
   String name;
   List<Person> people;
}

What is the best way to store and retrieve this on a database? Is this the best possible design for this kind of relationship?

War es hilfreich?

Lösung

in a relational database this is usually done using many-to-many relationships which are implemented using foreign keys in an intermediary table. foreign keys imply that the objects (your Person and Organisation) have primary keys (IDs). see for example here: http://en.wikipedia.org/wiki/Many-to-many_(data_model)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top