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.  [ 3 posts ] 
Author Message
 Post subject: Aggregation mapping
PostPosted: Tue Aug 28, 2007 9:07 pm 
Beginner
Beginner

Joined: Thu Aug 17, 2006 3:20 pm
Posts: 21
I am attempting to setup a multiplicity aggregation but not sure how I would accomplish this in the mappings.

Consider the following entities

Code:
public class Document : IContentItem
{
    private ContentItemBehavior _contentItemBehavior;
}

public class Image : IContentItem
{
    private ContentItemBehavior _contentItemBehavior;
}

public class ContentItemBehavior
{
    private IList<Tag> _tags;
}


ContentItemBehavior encapsulates common behavior of tagging, such as adding a tag, removing a tag and housing the collection of tags for the IContentItem.

The problem I am having is how to map the IList<Tag> collection within the Document and Image entities. Would I map the collection as the following:

Code:
<!-- Document mapping file -->
<bag name="ContentItemBehavior.Tags" table="ContentItem_Tag" cascade="all">
   <key column="ContentItemId"/>
   <many-to-many column="TagId"
      class="Tag"/>
</bag>


Also, the collection would be Bidirectional so on that note, in the Tag mapping file can I refer to the entity by the interface, or do I have to use the concrete type on the other end of the collection? like so:

Code:
<bag name="ContentItems" table="ContentItem_Tag" cascade="all">
   <key column="TagId"/>
   <many-to-many column="ContentItemId"
      class="IContentItem"/>
</bag>


I'm not sure if I can use interfaces to reference entities like that. If not, how would I accomplish this? I am trying to favor aggregation over inheritance. I suppose I would have to map ContentItemBehavior?

Thank you!

Sean


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 4:51 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Have you tried mapping your ContentItemBehavior as a component? Don't know if it would work without some additions:

Code:
<component name="ContentItemBehavior" >
   <bag name="ContentItemBehavior.Tags" table="ContentItem_Tag" cascade="all">
      <key column="ContentItemId"/>
      <many-to-many column="TagId" class="Tag"/>
   </bag>
</component>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 5:34 pm 
Beginner
Beginner

Joined: Thu Aug 17, 2006 3:20 pm
Posts: 21
i changed a little how the tags/content items are accessed. It made more sense within the domain, and for nhibernate.

Now whenever tags are used, all access will be performed through the Tag which will maintain the association. ContentItem will only have a reference to IList<Tag>.

Although this still creates a problem because on the Tag end, there is no way for me to tell what the ContentItem type is. ContentItem can be a Document, Link, Image etc..

I suppose I would have to use a discriminator and a many-to-many on both ends?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.