-->
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: [Resolved] Can't get component's property
PostPosted: Mon Jun 26, 2006 2:43 am 
Beginner
Beginner

Joined: Tue May 23, 2006 12:53 am
Posts: 34
I have a class named Article and under it I have a Section class, so I have something like this as my hbm.xml file.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
namespace="NBulletin.Core" assembly="NBulletin.Core">
   <class name="Article" table="Articles">
      <id name="Id" column="ArticleId" type="Int32">
         <generator class="identity"/>
      </id>
      <property name="Date" column="Date" type="DateTime"/>
      <property name="Keyword" column="Keyword" type="String"/>
      <property name="IsTopStory" column="IsTopStory" type="Boolean"/>
      <property name="ImageByte" column="Image" type="BinaryBlob"/>
      <property name="Text" column="Text" type="String"/>
      <property name="Caption" column="Caption" type="String"/>
      <property name="IsInactive" column="IsInactive" type="Boolean"/>
      <component name="Section" class="Section">
         <property name="Id" column="SectionId"/>
      </component>
      <bag name="Comments" cascade="all" access="nosetter.camelcase" lazy="false" inverse="true">
         <key column="ArticleId"/>
         <one-to-many class="Comment"/>
      </bag>
   </class>
</hibernate-mapping>

But when I load it, it won't load. I don't know where to find the thing I'm missing. Help please? Thanks!


Last edited by nebulom on Mon Jun 26, 2006 11:16 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 1:01 pm 
Beginner
Beginner

Joined: Sat Dec 10, 2005 6:22 pm
Posts: 28
Location: Chicago, IL
It looks like you are trying to use a component for a many-to-one mapping. If you have a table of Sections that you are trying to relate with the Id then it is a many-to-one. If however you have Section and all of its properties are stored in the Articles table then component is what you want. Usually components have more than just an Id field.

An example of a component in my project is a Name Class

Code:
<component name="Name" class="Crm.Domain.Objects.Name, Crm.Domain">
         <property name="FirstName" column="FirstName" type="String" length="32" not-null="true" />
         <property name="LastName" column="LastName" type="String" length="32" not-null="true" />
         <property name="MiddleName" column="MiddleName" type="String" length="32" not-null="true" />
         <property name="DisplayName" column="DisplayName" type="String" length="32" not-null="true" />
         <property name="Prefix" column="NamePrefix" type="String" length="16" not-null="true" />
         <property name="Suffix" column="NameSuffix" type="String" length="16" not-null="true" />
         <property name="Title" column="Title" type="String" length="32" not-null="true" />   
      </component>

All fields are stored in the table of the containing class. An example of a many to one.

Code:
<many-to-one  name="PickList" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" class="Crm.Domain.Objects.PickList, Crm.Domain" column="PickListKey" fetch="join" />


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 11:14 pm 
Beginner
Beginner

Joined: Tue May 23, 2006 12:53 am
Posts: 34
Thanks abombss. It's many to one indeed, I was wrong with component. The link is the foreign key of SectionId from Articles and SectionId(PK) of Sections. Again, thanks a bunch!


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.