Let me demonstrate a simple example,
Class Organization
- ID type Number,
- Name type String,
- HAS A -> Collection
Class Facility
- ID type Number,
- Name type String,
- Location String ,
- HAS A -> Organization
I am demonstrating a simple circular reference between two objects of an anemic data model. Assuming they are mapped to an ORM tool, a collection of Facility can be fetched lazily from an Organization, and likewise an Organization can be fetched lazily from a Facility.
I understand the convenience of this, at least on the middle tier. With a single Facility I can immediately obtain information about its Organization from code. My question then is:
Are there ANY other advantages to circular references in ORM mapped entities?
Despite my intense emotions on this subject right now, I am trying my best to not load the question...
The prime infuriating disadvantage I am sufferring through at this moment is when I am trying to serialize these objects into XML and send them across a web service, far from the lofty comforts of its benevolent ORM session. I can't serialize them as is because the ORM proxies cannot be sent, I must either eagerly fetch the child entities and send a MASSIVE object tree, or strip out the proxies from the graph.
Fair enough, so I wrote a utility to simply remove proxies, Great! It serializes and performance is salivatingly good, however when I get this object back from an UpdateEntity web service, it is missing the rest of the object graph, and now if I were to update this entity through the ORM, it thinks I have deleted all of these objects missing from the tree. No good.
I can't help but feel that circular references present a massive disadvantage in this scenario and I can't really seem to think of a good way to overcome this problem and the crippling performance problems I am tasked with solving without a data model redesign and massive refactoring.
What are your opinions on this? Is this indeed a design-smell?