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: Problems with many-to-one
PostPosted: Fri Nov 21, 2008 4:08 pm 
Newbie

Joined: Tue Nov 04, 2008 5:02 pm
Posts: 4
I seem to be having problems with the many-to-one association. I have an object that in the database has a foreignkey reference to a category object. If I don't attempt to link these to objects together in the mapping files (i.e. leave out the many-to-one association) they load fine (I've tested loading them both separately using their respective mapping files). However when I add in the many-to-one association, I get a LoadByUnqiueKey exception and the inner exception is "object reference not set to an instance of the object". Below is the mapping file with the many-to-one association:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GL.Objects" namespace="GL.Objects.Common">
   <class name="CodeDefinition" table="CodeDef" dynamic-update="true" dynamic-insert="true" select-before-update="true">
      <id name="ID" type="Int32" column="CodeDefID" unsaved-value="null" >
         <generator class="NHibernate.Id.IdentityGenerator" />
      </id>
      <property name="Value" column="CodeValue" type="Byte" />
      <property name="Description" column="CodeDescr" type="String" />
      <property name="UserAdded" column="UserAdded" type="String" />
      <property name="DateAdded" column="DateAdded" type="DateTime" />
      <property name="UserEdited" column="UserEdited" type="String" />
      <property name="DateEdited" column="DateEdited" type="DateTime" />
      <property name="IsDeleted" column="IsDeleted" type="Boolean" />
      <many-to-one name="Category" class="GL.Objects.Common.Category" column="CodeCategoryID" cascade="none" fetch="join" property-ref="ID" not-found="ignore" />
   </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GL.Objects" namespace="GL.Objects.Common">
   <class name="Category" table="CodeCategory" dynamic-update="true" dynamic-insert="true" select-before-update="true">
      <id name="ID" type="Int32" column="CodeCategoryID" unsaved-value="null" >
         <generator class="NHibernate.Id.IdentityGenerator" />
      </id>
      <property name="Name" column="CategoryDescr" type="String" />
      <property name="Notes" column="Notes" type="String" />
      <property name="UserAdded" column="UserAdded" type="String" />
      <property name="DateAdded" column="DateAdded" type="DateTime" />
      <property name="UserEdited" column="UserEdited" type="String" />
      <property name="DateEdited" column="DateEdited" type="DateTime" />
      <property name="IsDeleted" column="IsDeleted" type="Boolean" />
   </class>
</hibernate-mapping>



In the first mapping file, you'll see the many-to-one association. This seems to be item causing the problem but I can't figure out why. According to the documentation I have, this seems to be correct. Can anyone shed some light?

Thanks!

_________________
Shane A. McGarry
Senior Software Engineer


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 9:07 pm 
Newbie

Joined: Mon Jun 23, 2008 6:38 pm
Posts: 13
try

<many-to-one name="Category" class="GL.Objects.Common.Category, GL.Objects.Common" column="CodeCategoryID" cascade="none" fetch="join" property-ref="ID" not-found="ignore" />

instead of

<many-to-one name="Category" class="GL.Objects.Common.Category" column="CodeCategoryID" cascade="none" fetch="join" property-ref="ID" not-found="ignore" />


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.