-->
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: one-to-many mapping bug?
PostPosted: Fri Nov 17, 2006 3:18 pm 
Newbie

Joined: Wed Oct 25, 2006 2:05 pm
Posts: 6
Hibernate version: 1.2 beta 2 from svn

Database version: SQL Server 2005 (I use SQL2005Dialect)

Mapping documents: Here they are a bit simplified

Code:
<joined-subclass name="SmartBC.Entities.AddressBook.Person, SmartBC.Entities" table="Persons"
                extends="SmartBC.Entities.BusinessEntity, SmartBC.Entities">
      <key column="ID"/>
      <set name="Organizations" lazy="true" inverse="true">
         <key column="Organization" foreign-key="" />
         <one-to-many class="SmartBC.Entities.AddressBook.PersonOfOrganization, SmartBC.Entities"/>
      </set>
   </joined-subclass>
   
   <joined-subclass name="SmartBC.Entities.AddressBook.PersonOfOrganization, SmartBC.Entities" table="PersonsOfOrganization"
         extends="SmartBC.Entities.DomainObject, SmartBC.Entities">
      <key column="ID"/>
      <property name="PersonRole" type="Int32" column="Role" />
      <many-to-one name="Person" class="SmartBC.Entities.AddressBook.Person, SmartBC.Entities" column="Person" not-null="true" />
      <many-to-one name="Organization" class="SmartBC.Entities.AddressBook.Organization, SmartBC.Entities" column="Organization" not-null="true" />
   </joined-subclass>
   
   <joined-subclass name="SmartBC.Entities.AddressBook.Organization, SmartBC.Entities" table="Organizations"
                extends="SmartBC.Entities.BusinessEntity, SmartBC.Entities">
      <key column="ID"/>
      <set name="Persons" lazy="true" inverse="true">
         <key column="Person" />
         <one-to-many class="SmartBC.Entities.AddressBook.PersonOfOrganization, SmartBC.Entities" />
      </set>
   </joined-subclass>


So, the trouble is, that I can get correct PersonOfOrganization objects list with "from PersonOfOrganization", but Person.Organizations.Count is always zero, i.e. collections are not loaded. What I'm missing? *scratches head*


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 5:50 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Verify that you have data in the table.
Specifically, verify that there are rows that match
PersonsOfOrganization.Organization = Persons.ID

It looks to me that you have the wrong mapping in that you mapped a person id to organization id, and not to the person id.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 6:02 pm 
Newbie

Joined: Wed Oct 25, 2006 2:05 pm
Posts: 6
Oh my.... thank you ) It's too much caffeine and friday night after all .. I should sleep more )


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.