-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to use System.Data.SqlTypes nullable types?
PostPosted: Mon May 23, 2005 4:43 am 
Newbie

Joined: Mon May 23, 2005 4:10 am
Posts: 9
Hello!
I searched through the forums and documentation for this case but could not find anything. But in case I missed something, please forgive me!

Anyhow, tired of checking every nullable field for nothing'ness, I wanted to switch to the types used in the System.Data.SqlTypes namespace which have NULL-value compatibility. However, nHibernate cannot interpret these types and throws an exception:
Code:
Exception: NHibernate.MappingException
Message: could not interpret type: System.Data.SqlTypes.SqlInt64
Source: NHibernate
   at NHibernate.Cfg.Binder.GetTypeFromXML(XmlNode node)
   at NHibernate.Cfg.Binder.BindValue(XmlNode node, Value model, Boolean isNullable, String defaultColumnName)
   at NHibernate.Cfg.Binder.BindRootClass(XmlNode node, RootClass model, Mappings mappings)
   at NHibernate.Cfg.Binder.BindRoot(XmlDocument doc, Mappings model)
   at NHibernate.Cfg.Configuration.Add(XmlDocument doc)


I know it is possible to use user-defined types in hibernate, but I have no idea if and especially how it is possible to use .NET-framework integrated types.

Can anybody help me or give me a hint where to look for it?


further information:
we are using: VS.NET2003, using VB.NET ( :( ), nHibernate (incl. nUnit, nAnt, log4net, etc), SQL-Server 2000

thanks and cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 3:43 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
SqlTypes aren't supported out of the box right now, you'll have to write an IUserType implementation for them, but it should be pretty easy, just look at the docs for IUserType and at the Nullables implementation in NHibernateContrib.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 5:05 am 
Newbie

Joined: Mon May 23, 2005 4:10 am
Posts: 9
Hi

Thanks for your answer! I tried to implement a library which works similar to the Nullables.NHibernate, by combining System.Data.SqlTypes with the interface IUserType but failed :(

So I decided to use Nullables.dll and Nullables.NHibernate.dll. After lots of tweaking, adapting, etc I finally got it to compile and (partially) run. Unfortunatly another error came up which I have no clue how to solve. in the following fuction:
Code:
Private Function getSessionFactory() As ISessionFactory
   If _sessionFactory Is Nothing Then
      _sessionFactory = getConfiguration().BuildSessionFactory
   End If
   Return _sessionFactory
End Function

it works fine until the getConfiguration() part (where I have all the _configuration.AddClass(GetType(MyDTO)) and the connection properties) but it fails when getting to BuildSessionFactory. The error message is:
Code:
PonteVecchio.DTL.BothFundDAOTest.displayApprovedFunds : NHibernate.MappingException : Bad identifier type: NullableInt64Type

(sometimes it is NullableInt32Type instead... so not consistant either :?: )

and the last log4net message is:
Code:
2005-05-25 11:01:27,060 [2972] DEBUG NHibernate.Impl.SessionFactoryImpl [] <> - instantiating session factory with properties: hibernate.dialect=NHibernate.Dialect.MsSql2000Dialect;hibernate.show_sql=true;hibernate.connection.connection_string=***;hibernate.connection.provider=NHibernate.Connection.DriverConnectionProvider;hibernate.connection.driver_class=NHibernate.Driver.SqlClientDriver;


any ideas?


possible issues:
- that error message is thrown in AbstractEntityPersister
- I "extended" Nullables and Nullables.NHibernate by a NullableStringType. How come this doesn't exist? How do others map varchar fields?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 5:06 am 
Newbie

Joined: Mon May 23, 2005 4:10 am
Posts: 9
btw: Console.Error shows
Code:
log4net:ERROR DOMConfigurator: ConfigureFromXML called with null 'element' parameter


but that console window is usually not of much help to me..


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 11:38 am 
Newbie

Joined: Mon May 23, 2005 4:10 am
Posts: 9
I have tried further and just cannot get it to work.

Any input? *prettyplease*? :)

cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 11:52 am 
Contributor
Contributor

Joined: Thu May 12, 2005 12:59 pm
Posts: 20
Quote:
Bad identifier type: NullableInt64Type


NullableInt64Type doesn't implement IIdentifierType so it can't be used in id type="..."

Implementing IIdentifierType on NullableInt64Type wouldn't be much work. Just need to have a constant string - something like "FalseHasValue" - to indicate that NullableInt64.Default should be used.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 3:43 am 
Newbie

Joined: Mon May 23, 2005 4:10 am
Posts: 9
thanks for the answer (i didn't see it until now because the notification did not work :( ..)

unfortunatly, i don't really understand what you mean with you explanation. i couldn't find anything about IIdentifierType, neither for NullableInt64Type nor for any other IntXxType.

if i DO after all understand you correctly, should it work if i keep all nullabletypes and use regular longs (or Int64s) for the identity?


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