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>