Hello, I've searched around but can't seem to find an answer to what I assume is a common situation. In many cases, I have a relationship between entities that involves a collection, say Site, Page, and PageElement, where Site has a collection (Set) of Page instances, and a Page has a Set of PageElement instances. What I'd like to do is model the actual collection as a domain object so that I can add additional behavior to the collection.
So in this example, what I'd like is a PageCollection to model the collection of Pages associated with a Site. As an example, I may want to add a method called "hasPageElement()" to the collection, so that I can determine if a Site has a given PageElement in one of its Page instances. hasPageElement would exist in the PageCollection, and would loop over the Page instances in the collection looking for the specified PageElement.
I *could* add all this looping logic within Site, but I dislike forcing Site to reach across encapsulation boundaries though the Pages to look for the PageElement. Right now I create an entity called Pages to act as an intermediary, where Site has a oneToOne to Pages, and Pages contains a collection property of Page instances. That way I can add the method to Pages.
However, this seems hackish. I've looked at custom UserCollectionType as an option, but I'm not sure if that will do what I'm asking for, and I also haven't found a way to specify the custom collection type using an annotation. If there is a way to do this that I'm not aware of, please let me know.
This would seem to be a fairly common situation, where a collection of entities would work best if additional behavior could be attached to it. Am I missing something that would allow this? Thanks.
Brian
|