-->
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.  [ 1 post ] 
Author Message
 Post subject: optional to-One relationship to self, mapping question.
PostPosted: Wed Jun 30, 2004 12:49 pm 
Newbie

Joined: Wed Jun 30, 2004 11:00 am
Posts: 7
I'm just getting started with Hibernate (Version 2) and successfully created mapping files and .java source files for my entities.

I just have a question about one of the relationships in my model. I'm not sure the relationship is mapped properly.

For a little context, I'm writing web forum application. My "Message" entity has two relationships to itself. A to-Many called "messageReplies" and a to-One called "parentMessage".

The "parentMessage" relationship is optional. If it is null is simply means that this message is in direct reply to a "Topic" (which is a separate entity)

I used the middlegen tool to generate my files. I'm a little confused about how this relationships were generated. The two columns that make up this relationship is MESSAGE_ID (the pk) and PARENT_MESSAGE id.

I'm curious why I don't see any references to MESSAGE_ID in these relationship mappings. Shouldn't they be there?

Also, since the "parentMessage" relationship is optional, should the not-null="true" be changed to not-null="false"?

Thanks in advance,
Eric

Code:
   
<!-- bi-directional one-to-many association to Message -->
    <set
        name="messageReplies"
        lazy="true"
        inverse="true"
    >
        <meta attribute="field-description">
           @hibernate.set
            lazy="true"
            inverse="true"

          @hibernate.collection-key
           column="PARENT_MESSAGE_ID"

           @hibernate.collection-one-to-many
            class="dumas.services.messageboard.Message"
        </meta>
        <key>
            <column name="PARENT_MESSAGE_ID" />
        </key>
        <one-to-many
            class="dumas.services.messageboard.Message"
        />
    </set>
   
    <!-- bi-directional many-to-one association to Message -->
    <many-to-one
        name="parentMessage"
        class="dumas.services.messageboard.Message"
        not-null="true"
    >
        <meta attribute="field-description">
           @hibernate.many-to-one
            not-null="true"
           @hibernate.column name="PARENT_MESSAGE_ID"         
        </meta>
        <column name="PARENT_MESSAGE_ID" />
    </many-to-one>


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

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.