-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Model a Collection as a Domain Object?
PostPosted: Wed Sep 30, 2009 1:59 pm 
Newbie

Joined: Thu Sep 25, 2008 3:06 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Model a Collection as a Domain Object?
PostPosted: Wed Oct 28, 2009 1:00 pm 
Newbie

Joined: Thu Sep 25, 2008 3:06 am
Posts: 2
Hi, it's been a while since I asked about this but no one seems to have much to say. Really? I'm alone in wanting to attach additional behavior to a domain object that is a collection? Am I missing something obvious that makes this easy to do? Or possibly missing something obvious that makes this a bad idea? Any advice appreciated!

Thanks,

Brian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.