D
Dr.J
Hi All. I was hoping for some feedback on how others manage a deep
copy between two entities when they share a bidirectional association.
For illustration, consider the two entities Person and Address where a
Person can be associated with multiple addresses, an Address can be
associated with multiple Persons, and there is a requirement that
Person must know of its Addresses and Address must know of its
Persons.
As a result of performing a 100% deep copy with this type of
association you can end up with infinite recursion:
- Make a copy one of the Person requires that a copy is made of
each Address with which it is associated
- Making a copy of each Address requires that a copy is made of
each Person with which it is associated
- ad nauseum ...
While this problem is independent of the cardinality of the
association, there are some likely solutions when you make assumptions
about the association. For example, if 1:1 and the entities are simple
(not complex graphs with even more entity associations) then you could
copy each entity separately and then recreate the association.
No doubt there are a known suite of solutions to this problem but I
have been unable to track them down. To that end, any pointers would
be gratefully accepted. Furthermore, this is really a generic
programming question but one that I hoped would be of benefit to the
list.
TIA
copy between two entities when they share a bidirectional association.
For illustration, consider the two entities Person and Address where a
Person can be associated with multiple addresses, an Address can be
associated with multiple Persons, and there is a requirement that
Person must know of its Addresses and Address must know of its
Persons.
As a result of performing a 100% deep copy with this type of
association you can end up with infinite recursion:
- Make a copy one of the Person requires that a copy is made of
each Address with which it is associated
- Making a copy of each Address requires that a copy is made of
each Person with which it is associated
- ad nauseum ...
While this problem is independent of the cardinality of the
association, there are some likely solutions when you make assumptions
about the association. For example, if 1:1 and the entities are simple
(not complex graphs with even more entity associations) then you could
copy each entity separately and then recreate the association.
No doubt there are a known suite of solutions to this problem but I
have been unable to track them down. To that end, any pointers would
be gratefully accepted. Furthermore, this is really a generic
programming question but one that I hoped would be of benefit to the
list.
TIA