-->
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.  [ 4 posts ] 
Author Message
 Post subject: ID property doesn't get set after upgrading to V1.0
PostPosted: Tue Nov 08, 2005 7:11 am 
Newbie

Joined: Tue Nov 08, 2005 6:57 am
Posts: 3
Hi,

I wanted to upgrade NHibernate from 0.6 which is currently used by my WinForms App to Version 1.0.

After a few minor changes in the code I got it compiling but everytime a business object gets loaded everything BUT the ID property is loaded.

I have a base class called BusinessObject (the NHibernate mapping files only know about the derived classes) with a GUID ID property, but I also tried it with a string property with the same result.

I tried to debug into NHibernate (not too deep I have to admit) but didn't find any valualble info (the ID simply isn't in the LoadedValues array).

Did anyone see a similar problem?

Thanks
Andi


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 10:46 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Can you give more details? The mapping of the ID, the executed code, the content of the log...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 5:34 pm 
Newbie

Joined: Tue Nov 08, 2005 6:57 am
Posts: 3
I isolated the problem as much as I could.

This is the mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <!-- WatchDogEntry                             -->
   <!-- ***************************************** -->
   <class name="SilverBytes.BSL.DomainModel.Core.WatchDogEntry, SilverBytes.BSL.DomainModel"
      table="WatchDogEntry">
      <id name="Id" column="Id" unsaved-value="null" >
         <generator class="assigned" />
      </id>
      <property name="Login" />
      <property name="IpAddress" />
      <property name="MachineName" />
      <property name="TimeStamp" />
   </class>
</hibernate-mapping>


The WatchdogEntry class is straight forward (not inheriting from any class). The constructor sets the Id to a new guid value.

I think the App.config is quite normal as well:
Code:
   <nhibernate>
      <session-factory name="NHibernate.Test">
         <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
         <add key="dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
         <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
         <add key="connection.connection_string" value="my connection string" />
         <add key="use_outer_join" value="false" />
      </session-factory>
   </nhibernate>


The log output (Nhibernate DEBUG) can be found at http://www.silverbytes.at/test.log

The testcase to reproduce this looks like this:
Code:
      [Test]
      public void StoreWatchDogEntry()
      {
         Guid myGuid =  Guid.NewGuid();
         WatchDogEntry wdEntry = new WatchDogEntry("hello", "ip", "machine");
         wdEntry.Id = myGuid;
            Session.Save(wdEntry);
         Session.Flush();

         RefreshSession();

         IList foundObjects = Session.Find("from WatchDogEntry as wde where wde.Id = ?", myGuid, NHibernateUtil.Guid);
         wdEntry = (WatchDogEntry) foundObjects[0];
         Assert.AreEqual(myGuid, wdEntry.Id);
      }


The test output tells the following:
Quote:
TestCase 'SilverBytes.DomainModel.WatchDogFixture.StoreWatchDogEntry' failed:
expected:<5d5247eb-458e-4506-99fa-d6fe9f80a03c>
but was:<33895e8f-c1d9-4145-91fe-ead5d4e70f85>
c:\dev\vaa


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 12:44 pm 
Newbie

Joined: Tue Nov 08, 2005 6:57 am
Posts: 3
OK, finally I figured it out myself: The reason for the key properties not getting set is that I'm providing an implementation for IInterceptor.Instantiate which in the current version has to set the key properties itself. In Version 0.6 NHibernate took care of that.

It would be great if the implementation of Instantiate could specify if it did set the key properties. In the current implementation the interceptor has to know the key properties for every business class or every business class implements an interface for setting them (this is the way I've choosen now).

Or is there any convenient helper function which sets the key properties for me (using the NHibernate-Mapping)?

Greetings,
Andi


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