Bug in NHibernate 2.0 Beta 1 relating to Custom Types - Resolved in Beta 2
 

Started working with NHibernate last week, and while hooking up my POCO to
SQL Server TimeStamp field type, found a bug in the 2.0 (Beta 1) code base.

In the CustomType class constructor, the name field is getting set to the
userTypeClass.Name property (line 33).

This causes an exception to be thrown when NHibernate tries to use your
custom type since it can't get to it if not fully qualified.

The fix is simple:

change:
name = userTypeClass.Name;
to
name = userTypeClass.AssemblyQualifiedName;

Update (14-July-2008): This has been resolved in the 2.0 Beta 2
code base.


Happy Coding!


Comments (8) -

Philip Japikse
8/21/2009 2:43:11 AM #

In your mapping files, do you have the version tag set correctly?

Use something like this:

<version name="RowVersion" column="LastModified"
     type="Pinnacle.NHibernate.Utilities.UserTypeTimestamp,Pinnacle.NHibernate.Utilities"
     generated="always" unsaved-value="null"/>

Rama Attaluri
8/21/2009 7:43:11 AM #

The element that is causing this error is a user defined type. And the exception that I see is:

Unhandled Exception: NHibernate.MappingException: Could not compile the mapping document: TestUser.hbm.xml ---> NHibernate.MappingException: Could not determine type for: MyTest.SiteUserId, MyTest, for columns: NHibernate.Mapping.Column(Id)   at NHibernate.Mapping.SimpleValue.get_Type() in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Mapping\SimpleValue.cs:line 239
at NHibernate.Cfg.XmlHbmBinding.ClassIdBinder.CreateIdentifierProperty(HbmId idSchema, PersistentClass rootClass, SimpleValue id) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\XmlHbmBinding\ClassIdBinder.cs:line 69
   at NHibernate.Cfg.XmlHbmBinding.ClassIdBinder.BindId(HbmId idSchema, PersistentClass rootClass, Table table) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\XmlHbmBinding\ClassIdBinder.cs:line 31
   at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node, HbmClass classSchema) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\XmlHbmBinding\RootClassBinder.cs:line 48
   at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode parentNode) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\XmlHbmBinding\MappingRootBinder.cs:line 67
   at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\XmlHbmBinding\MappingRootBinder.cs:line 30
   at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 431
   --- End of inner exception stack trace ---
   at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 262
   at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 436
   at NHibernate.Cfg.Configuration.ProcessMappingsQueue() in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1557
   at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1548
   at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1541
   at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 506
   at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 544

Philip Japikse
8/21/2009 12:43:11 PM #

I just updated everything to CR2 (see my post for compiling CR2 in VS2008 and the 3.5 FW), and it worked fine.  All of my tests passed.  What is the error that you are getting?  (I will check my post on the custom class to make sure it's current, but won't get to that until tomorrow.)

Rama Attaluri
8/21/2009 5:43:11 PM #

Have you tried this out in the beta2 release? I still see this bug, even with the NHibernate 2.0 CR2 source.

Thanks.

Philip Japikse
8/21/2009 10:43:11 PM #

Beta 2 codebase fixed this bug.

Philip Japikse
8/22/2009 3:43:11 AM #

Ok, I didn't follow the correct process on my first bug report.  I created a new bug with sample code and tests, etc. here http://jira.nhibernate.org/browse/NH-1377

Philip Japikse
8/22/2009 8:43:11 AM #

I did, and the response was that it is a non-issue.  I responded with the link to the sample code that I used to discover the issue (probably should have done that first).

mallen
8/22/2009 1:43:11 PM #

Hi,

Have you logged this issue on jira?
http://jira.nhibernate.org/secure/Dashboard.jspa

Comments are closed

.NET Musings

Wandering thoughts of a developer, architect, speaker, and trainer

Managed Windows Shared Hosting by OrcsWeb