cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Friedrich Röhrs <>
Subject Many-To-Many Relationships and editing them via ToManyList
Date Sun, 26 Aug 2012 11:17:26 GMT

I am a bit confused about ToManyList and if I have understood
correctly how they work.

My Tables are as follows:


The Classes generated from this are: Person and Building.

I have modelled it so that Person.getBuildings() would return a list
of buildings that person has access to (going through PERSON_BUILDING
via flattened relationships) and Building.getPersons() would get the
persons allowed into that building.

For me the simplest (and most natural) way of adding/removing access
would be something like this:

Person p = PersonService.getById(id);
Building b = BuildingService.getById(id2);

Person p2 = PersonService.getById(id3);
List<Building> bs = BuildingService.getAllById(listOfIds);


(and then commit).

For my simple test this seems to work. But when cayenne generates the
domain classes it creates additional methods:

Person.removeFromBuildings(Building b);
Person.addToBuildings(Building b);

and same for Buildings. This seems redundant if one can already do
this by editing the list to me, so I was a bit confused.

Furthermore I found a Mailinglist entry that said if one doesn't use
the provider methods, reverse relationships are not removed.

For me the reverse relationship of Person -> Building is Building ->
Person, but this hinges on the same table entry in PERSON_BUILDING, so
if I delete it, the reverse Relationship should be gone too, no?

Also all examples in the docs and demos, use the generated methods, so
I am unsure if I can use the ToManyList directly or if that will
somehow break something later.



View raw message