-->
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: Problem with Collection when upgrading from 0.6 to 0.8.4
PostPosted: Tue May 31, 2005 4:03 pm 
I've just updated from 0.6 to 0.84 and am having trouble with a simple set mapping. There are records in the database but when I try and interate through the collection there's nothing there. This worked fine in 0.6.

Code:
<set name="Facilities" lazy="true" inverse="true" cascade="all">
    <key column="PRACTICE_ID" />
    <one-to-many class="PLI.Model.Data.PracticeFacility, Model" />
</set>


Code:
Practice prac = (Practice)session.Get(typeof(Practice), 3);
System.Console.WriteLine(prac.Name);
System.Console.WriteLine("Facility count: ", prac.Facilities.Count.ToString());
for (IEnumerator en = prac.Facilities.GetEnumerator(); en.MoveNext(); )
    {
         System.Console.WriteLine((PracticeFacility)en.Current);
    }


the log wrote:
2005-05-31 13:56:08,163 [3164] INFO NHibernate.Impl.SessionImpl [] - uninitialized collection: in
itializing
2005-05-31 13:56:09,746 [3164] INFO NHibernate.Impl.SessionImpl [] - new collection: instantiating
2005-05-31 13:56:09,776 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,776 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,776 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,786 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,786 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,786 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,796 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,796 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,796 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,796 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,806 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,806 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,806 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,806 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,816 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,816 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,816 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
2005-05-31 13:56:09,826 [3164] INFO NHibernate.Impl.SessionImpl [] - reading row
Facility count:


As you can see it's reading records from the database, but they don't end up in the collection!

Also, an HQL query of "select elements(p.Facilities) from PLI.Model.Data.Practice p where p.PracticeID = :practiceID" yields the expected results, a list of objects.

Since this worked previously in 0.6 and the HQL works I'm confident the mapping is correct. I've got other places with mappings/code that's almost identical and they work. Anyone run into this or have any ideas?

Thanks,

Michael


Top
  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 2:40 pm 
Ok, I've stepped debugged this and it's a fun one. It has to do with the id type. My practice class id is an Int64, in the code above I load practice 3. 3 is an int (Int32) so in SessionImpl.GetLoadingCollection it creates a CollectionKey using this id. But when it queries for facilities it gets smart and realizes the practice id is an Int64 so when it tries to lookup the collection (so it can add new items) it doesn't find it. Because the CollectionKey object has an Int32 in it instead of an Int64 even though they both contain the number 3 which is the id. Make sense? I have new respect for this NHibernate team after stepping through many lines of this code. But I'm hoping they know what I'm talking about and can fix it to work the way it used to in 0.6 so someone else doesn't come across this not at all straight forward bug. Because I like the old math where 3 = 3 no matter what the type. :)

Thanks,
Michael


Top
  
 
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.