-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping Problem With Composite Ids
PostPosted: Tue May 26, 2009 8:44 am 
Newbie

Joined: Tue May 26, 2009 8:26 am
Posts: 1
Hey guys,

I recently managed to convince my colleagues to use NHibernate for persistence. So now I have to deal with it, without knowing very much about using Hibernate. At the moment I've got a problem with my mapping. I want to attach several arguments to a monitor. The arguments have got a composite-id, which I think must have something to do with the problem as all other one-to-manys are working fine.

ARGUMENT
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <class name="Foo.Model.HArgument, SelmaDb" table="argument">
        <composite-id name="HArgumentPK" class="Foo.Model.HArgumentPK">
          <key-property name="MonitorId" column="monitor_id" type="integer"/>
          <key-property name="Position" column="position" type="integer"/>
        </composite-id>
        <many-to-one name="Monitor" column="monitor_id" class="Foo.Model.HMonitor"/>
        <property name="Value" column="value" type="String" length="255"/>
    </class>
</hibernate-mapping>



MONITOR
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <class name="Foo.Model.HMonitor, SelmaDb" table="monitor">
        <id name="Id" column="id" type="Int32">
            <generator class="identity" />
        </id>
        <many-to-one name="Client" column="client_id" class="Foo.Model.HClient"/>
        <many-to-one name="Command" column="command_id" class="Foo.Model.HCommand"/>
        <property name="Interval" column="interval" type="Int32"/>
        <bag name="Arguments" cascade="none" lazy="true">
          <key column="monitor_id"/>
          <one-to-many class="Foo.Model.HArgument"/>
        </bag>
    </class>
</hibernate-mapping>



Skeleton classes
Code:
public class HArgument
    {
        #region orm specific
        public virtual HMonitor Monitor { get; set; }
        public virtual int Position { get; set; }
        public virtual string Value { get; set; }
        #endregion
....


Code:
public class HMonitor
    {
        #region orm specific
        public virtual int Id { get; set; }
        public virtual HClient Client { get; set; }
        public virtual HCommand Command { get; set; }
        public virtual int Interval { get; set; }
        public virtual IList<HArgument> Arguments { get; set; }
        #endregion
.....



When i build the session factory I get the following error: "Association references unmapped class: Foo.Model.HArgument". If I don't use the <bag> Tag in the HMonitor.hbm.xml it seems to work fine (at least I get the app to run as it should).


I think the solution must be really easy, I just don't seem to get it right...
Thanks for your help in advance,
peace
Hybris


Top
 Profile  
 
 Post subject: Re: Mapping Problem With Composite Ids
PostPosted: Wed May 27, 2009 4:19 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Which way do you use to "register" classes for hibernate ? If you use AddAssembly, check if the mapping file is set to build action "Embedded Resource".

_________________
--Wolfgang


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