-->
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.  [ 8 posts ] 
Author Message
 Post subject: one-to-two relation
PostPosted: Wed Aug 04, 2004 5:13 am 
Newbie

Joined: Tue Jul 20, 2004 7:03 am
Posts: 19
Location: Spain
Hi all:

This is a mapping-howto question

I have 2 classes:

-VersionedContent
-Content

There is a relation
VersionedContent --------------- Content
(one to two)

How can i best model it ?

THANKS.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 9:15 am 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
I think that you must to create two attributes Content in the VersionedContent class and so map each attributes like a one-to-one. This is simple and probably will work fine in your case. ;-)

valeuz...

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject: solution
PostPosted: Thu Aug 05, 2004 4:52 am 
Newbie

Joined: Tue Jul 20, 2004 7:03 am
Posts: 19
Location: Spain
Well, my solution is:

Code:
      <map name="relatedContents" cascade="all">
         <key column="keyRelContent"/>
         <!-- the index will be DRAFT or PUBLISHED -->
         <index column="publisherStatusIndexVersContent" type="java.lang.Integer"/>
         <one-to-many class="com.zz.contentManagement.model.Content"/>
      </map>


Then, into the VersionedContent Objet i have...

Code:
   public Content getPublishedContent() {
      if (this.getRelatedContents() == null
         || this.getRelatedContents().isEmpty()) {
         com.zzz.util.log.LogUtil.getDebugLogger().warn(
            "Inconsistent model, there is no map assigned for versioned content id = "
               + this.getId());
         return null;
      } else {
         return (Content) this.getRelatedContents().get(
            VersionedContent.RELATED_CONTENT_INDEX_PUBLISHED);
      }
   }

   public void setPublishedContent(Content content) {
      if (this.getRelatedContents() == null) {
         com.oneplanettravel.util.log.LogUtil.getDebugLogger().warn(
            "creating content map for VersionedContent = " + this.getId());
         this.setRelatedContents(new HashMap());
      }

      this.getRelatedContents().put(
         VersionedContent.RELATED_CONTENT_INDEX_PUBLISHED,
         content);

   }

   public Content getDraftContent() {
      if (this.getRelatedContents() == null
         || this.getRelatedContents().isEmpty()) {
         com.zzz.util.log.LogUtil.getDebugLogger().warn(
            "Inconsistent model, there is no map assigned for versioned content id = "
               + this.getId());
         return null;
      } else {
         return (Content) this.getRelatedContents().get(
            VersionedContent.RELATED_CONTENT_INDEX_DRAFT);
      }
   }

   public void setDraftContent(Content content) {
      if (this.getRelatedContents() == null) {
         com.zzz.util.log.LogUtil.getDebugLogger().warn(
            "creating content map for VersionedContent = " + this.getId());
         this.setRelatedContents(new HashMap());
      }

      this.getRelatedContents().put(
         VersionedContent.RELATED_CONTENT_INDEX_DRAFT,
         content);
   }



This is not so clean, but leaves the door open to a more complex version system (now there is only a 'one level' deep).

Thanks


Top
 Profile  
 
 Post subject: Re: solution
PostPosted: Thu Aug 05, 2004 5:02 am 
Beginner
Beginner

Joined: Mon Aug 02, 2004 1:08 pm
Posts: 42
I also don't understand why don't you just map two properties publishedContent and draftContent.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 10:43 am 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
IMHO you are adding unnecessary complexity to your model. If you really need only a one-2-two relationship, create two attributes and map each one them like a one-to-one seems more correct. At least for me.

valeuz...

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 1:30 pm 
Newbie

Joined: Tue Jul 20, 2004 7:03 am
Posts: 19
Location: Spain
Ok, i'll do

I've used this approach because when i've used the "two one-to-one" approach, there were an error and i was saving the same object twice.

I didn't know how to solve this, so i did use the other dirty way.

Let's smite that demon...


Top
 Profile  
 
 Post subject: Doesn't work...
PostPosted: Tue Aug 10, 2004 9:58 am 
Newbie

Joined: Tue Jul 20, 2004 7:03 am
Posts: 19
Location: Spain
Sorry, how can i do that mapping?

I used one-to-one, with this mapping


Code:
      <one-to-one name="draft" class="com.zzz.contentManagement.model.Content" cascade="all" />
      <one-to-one name="published" class="com.zzz.contentManagement.model.Content" cascade="all" />



But BOTH one-to-one mappings point to the SAME object (is this the expected behaviour?)

Sorry, i'm a newbe. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 9:49 am 
Newbie

Joined: Tue Jul 20, 2004 7:03 am
Posts: 19
Location: Spain
SOLUTION

Anter reading a lot, finally the working mapping is...

Code:
      <many-to-one name="draft"
         class="com.zzz.contentManagement.model.Content"
         column="draft_idContent"
         cascade="all"
         unique="true"/>

      <many-to-one name="published"
         class="com.zzz.contentManagement.model.Content"
         column="published_idContent"
         cascade="all"
         unique="true"/>



Thanks!


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