I have a situation in which I need to map back to an sql_variant column in MSSQL 2008. The data model is set so I have no other options at this point.
I realize I need to implement a custom IUserType and found this thread for reference: https://forum.hibernate.org/viewtopic.php?t=987576 I've implemented the type per that thread, now I have the following Entity: public abstract class AbstractProperty { public virtual int Id { get; protected set; } public virtual string Name { get; protected set; } public virtual object Value { get; set; } public virtual BusinessEntity BusinessEntity { get; protected set; } ... } followed by the following mapping file: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default- access="property" auto-import="true" default-cascade="none" default- lazy="true"> <class xmlns="urn:nhibernate-mapping-2.2" name="Characteristics.Core.Domain.AbstractProperty, Characteristics.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="AbstractProperties"> <id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <column name="AbstractPropertyId" /> <generator class="identity" /> </id> <discriminator type="String"> <column name="discriminator" /> </discriminator> <property name="Value" type="Characteristics.Data.Persistence.UserTypes.SqlVariant, Characteristics.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> <column name="Value" /> </property> <property name="Name" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <column name="Name" /> </property> <property name="DateCreated" type="System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <column name="DateCreated" /> </property> <property name="LastModified" type="System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <column name="LastModified" /> </property> <many-to-one class="Characteristics.Core.Domain.BusinessEntity, Characteristics.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="BusinessEntity"> <column name="BusinessEntityId" /> </many-to-one> <subclass name="Characteristics.Core.Domain.IntProperty, Characteristics.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> <subclass name="Characteristics.Core.Domain.DecimalProperty, Characteristics.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> <subclass name="Characteristics.Core.Domain.StringProperty, Characteristics.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> </class> </hibernate-mapping> All seems to be right from what I understand about NH, but when I run the integration test and try to generate a schema, I get a "SystemArgumentException: Dialect does not support DbType.Object" at NHibernate.Dialect.TypeNames.Get(DbType typecode) at NHibernate.Dialect.Dialect.GetTypeName(SqlType sqlType) at NHibernate.Mapping.Column.GetDialectTypeName(Dialect dialect, IMapping mapping) at NHibernate.Mapping.Column.GetSqlType(Dialect dialect, IMapping mapping) at NHibernate.Mapping.Table.SqlCreateString(Dialect dialect, IMapping p, String defaultCatalog, String defaultSchema) at NHibernate.Cfg.Configuration.GenerateSchemaCreationScript(Dialect dialect) at NHibernate.Tool.hbm2ddl.SchemaExport..ctor(Configuration cfg, IDictionary`2 configProperties) at NHibernate.Tool.hbm2ddl.SchemaExport..ctor(Configuration cfg) at Core.Test.Data.NHibernate.RepositoryTestHelper.InitializeDatabase (String fileName) in C:\Documents and Settings\Devon\My Documents \Visual Studio 2008\Projects\CoreFramework\src\Core.Test\Data \NHibernate\RepositoryTestHelper.cs:line 45 at Core.Test.Data.NHibernate.RepositoryTestHelper.InitializeDatabase() in C:\Documents and Settings\Devon\My Documents\Visual Studio 2008\Projects\CoreFramework\src\Core.Test\Data\NHibernate \RepositoryTestHelper.cs:line 30 at Characteristics.Test.Integration.Data.Persistence.NHibernateFixture.CanGenerateSchema () in C:\Documents and Settings\Devon\My Documents\Visual Studio 2008\Projects\Characteristics\trunk\src\Characteristics.Test \Integration\Data\Persistence\NHibernateFixture.cs:line 13 Looking at the code in NHibernate.Dialect.MsSql2008Dialect and NHibernate.Dialect.MsSql2005Dialect, sure enough, it looks like DbType.Object is not configured. Does NH support the use of DbType.Object? I'm thinking I must be missing something. Regards, -devon
-- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
