Hi All,
Just trying to migrate from MS SQL Server -> DB2 and having a few issues. I seem to be able to use Objects without boolean mappings fine but booleans seem to cause a few headaches.
My hib.cfg.xml is pretty straight forward:
Code:
<session-factory name="SF">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.DB2Driver</property>
<property name="dialect">NHibernate.Dialect.DB2Dialect</property>
<property name="connection.connection_string">PWD=db2admin;UID=db2admin;Database=RSv3_0</property>
<property name="show_sql">true</property>
<property name="hibernate.cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider,NHibernate.Caches.SysCache</property>
<property name="hibernate.cache.use_query_cache">true</property>
</session-factory>
My Object mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="PicNet.RiskShield.DAL.User, RiskShieldDAL" table="`User`">
<jcs-cache usage="read-write"/>
<id name="ID" column="`UserID`" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="BusinessUnit" column="`BusinessUnitID`" not-null="false"/>
<property name="UserPassword" column="`UserPassword`" type="String" not-null="true" length="25"/>
<property name="FirstName" column="`FirstName`" type="String" not-null="true" length="50"/>
<property name="LastName" column="`LastName`" type="String" length="50"/>
<property name="Email" column="`Email`" type="String" not-null="true" length="150"/>
<property name="IsEnterprise" column="`IsEnterprise`" type="Boolean" not-null="true"/>
<property name="IsSystemAdministrator" column="`IsSystemAdministrator`" type="Boolean" not-null="true"/>
<property name="IsActive" column="`IsActive`" type="Boolean" not-null="true"/>
</class>
</hibernate-mapping>
An excerpt from the hib.log:
Code:
2005-07-18 17:25:53,483 [1660] DEBUG NHibernate.Engine.Cascades [] <> - unsaved-value: 0
2005-07-18 17:25:53,483 [1660] DEBUG NHibernate.Impl.SessionImpl [] <> - SaveOrUpdate() unsaved instance
2005-07-18 17:25:53,483 [1660] DEBUG NHibernate.Impl.SessionImpl [] <> - calling OnSave()
2005-07-18 17:25:53,499 [1660] INFO NHibernate.Impl.SessionImpl [] <> - executing insertions
2005-07-18 17:25:53,499 [1660] DEBUG NHibernate.Persister.EntityPersister [] <> - Inserting entity: PicNet.RiskShield.DAL.User (native id)
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Impl.BatcherImpl [] <> - Building an IDbCommand object for the SqlString: INSERT INTO "User" ("LastName", "IsSystemAdministrator", "FirstName", "Email", "UserPassword", "IsActive", "IsEnterprise", "BusinessUnitID", "UserID") VALUES (:"LastName", :"IsSystemAdministrator", :"FirstName", :"Email", :"UserPassword", :"IsActive", :"IsEnterprise", :"BusinessUnitID", default)
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Impl.BatcherImpl [] <> - about to open: 0 open IDbCommands, 0 open DataReaders
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Impl.BatcherImpl [] <> - Building an IDbCommand object for the SqlString: values IDENTITY_VAL_LOCAL()
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Persister.EntityPersister [] <> - Dehydrating entity: PicNet.RiskShield.DAL.User#
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Type.NullableType [] <> - binding 'Last Name' to parameter: 0
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Type.NullableType [] <> - binding 'True' to parameter: 1
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Type.NullableType [] <> - binding 'First Name' to parameter: 2
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Type.NullableType [] <> - binding 'email@email.com' to parameter: 3
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Type.NullableType [] <> - binding 'pwd' to parameter: 4
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Type.NullableType [] <> - binding 'True' to parameter: 5
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Type.NullableType [] <> - binding 'True' to parameter: 6
2005-07-18 17:25:53,514 [1660] DEBUG NHibernate.Type.NullableType [] <> - binding '1' to parameter: 7
2005-07-18 17:25:53,514 [1660] INFO NHibernate.Impl.BatcherImpl [] <> - Preparing INSERT INTO "User" ("LastName", "IsSystemAdministrator", "FirstName", "Email", "UserPassword", "IsActive", "IsEnterprise", "BusinessUnitID", "UserID") VALUES (?, ?, ?, ?, ?, ?, ?, ?, default)
2005-07-18 17:25:53,546 [1660] ERROR NHibernate.Persister.EntityPersister [] <> - Specified cast is not valid.
Exception: System.InvalidCastException
Message: Specified cast is not valid.
Source: IBM.Data.DB2
at IBM.Data.DB2.DB2Parameter.b(h& A_0)
at IBM.Data.DB2.DB2Parameter.c(h& A_0)
at IBM.Data.DB2.DB2ParameterCollection.g()
at IBM.Data.DB2.DB2Command.b()
at IBM.Data.DB2.DB2Command.ExecuteNonQuery()
at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Persister.EntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlString sql, Object obj, ISessionImplementor session)
2005-07-18 17:25:53,546 [1660] DEBUG NHibernate.Impl.BatcherImpl [] <> - done closing: 0 open IDbCommands, 0 open DataReaders
2005-07-18 17:25:53,546 [1660] DEBUG NHibernate.Impl.BatcherImpl [] <> - done closing: -1 open IDbCommands, 0 open DataReaders
2005-07-18 17:25:53,546 [1660] ERROR NHibernate.ADOException [] <> - Could not save object
Exception: System.InvalidCastException
Message: Specified cast is not valid.
Source: IBM.Data.DB2
at IBM.Data.DB2.DB2Parameter.b(h& A_0)
at IBM.Data.DB2.DB2Parameter.c(h& A_0)
at IBM.Data.DB2.DB2ParameterCollection.g()
at IBM.Data.DB2.DB2Command.b()
at IBM.Data.DB2.DB2Command.ExecuteNonQuery()
at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Persister.EntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlString sql, Object obj, ISessionImplementor session)
at NHibernate.Persister.EntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledIdentityInsertion.Execute()
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Key key, IClassPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IClassPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
2005-07-18 17:25:53,546 [1660] DEBUG NHibernate.Transaction.AdoTransaction [] <> - rollback
2005-07-18 17:25:53,561 [1660] DEBUG NHibernate.Impl.SessionImpl [] <> - transaction completion
2005-07-18 17:25:53,561 [1660] DEBUG NHibernate.Impl.SessionImpl [] <> - running ISession.Dispose()
2005-07-18 17:25:53,561 [1660] DEBUG NHibernate.Connection.ConnectionProvider [] <> - Closing connection
2005-07-18 17:25:53,561 [1660] DEBUG NHibernate.Transaction.AdoTransaction [] <> - running AdoTransaction.Dispose()
2005-07-18 17:25:53,561 [1660] DEBUG NHibernate.Impl.BatcherImpl [] <> - running BatcherImpl.Dispose()
Any help greatly appreciated.
Thanks All
Guido Tapia