I have been working with NHibernate 0.8.4 with some success, but the switch to letting NHibernate manage the key generation has failed for me.
Perhaps I have missed a configuration requirement for SQL Server. As a troubleshooting step I have tested my code with the generator class=assigned and everything works. However, when I go to native or identity, it appears that NHiberate is trying to insert the object without populating the primary key field thus causing an exception.
I have tried experimenting with the unsaved-value and explicit initialization, but with no success. Notice in the log that it does not attempt to insert a value for the primary key.
The success log is the assigned case.
I don't have the exception to include, but it is essentially a constraint violation because trying to add either a null field or a value that already exists for the primary key.
Any help would be appreciated as I am running out of troubleshooting ideas and need another set of eyes.
Let me review some of the details:
Persistence Class:
Code:
public class Balance
{
private Int32 id;
private DateTime busDate;
//etc
public Balance()
{
}
public Int32 Id
{
get { return id; }
set { id = value; }
}
//etc
Mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="CohenSteers.AssetCoverage.Persistence.Balance, ACMReporter" table="BALANCE_TBL">
<id name="Id" column="ID" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="BusinessDate" column="BUS_DATE" type="DateTime"/>
etc, etc
Failure Log:
2005-06-21 20:33:59,738 [2572] INFO NHibernate.Cfg.Configuration instantiating and configuring caches
2005-06-21 20:33:59,738 [2572] INFO NHibernate.Impl.SessionFactoryImpl building session factory
2005-06-21 20:33:59,831 [2572] INFO NHibernate.Impl.SessionFactoryObjectFactory no name configured
2005-06-21 20:34:03,785 [2572] INFO NHibernate.Impl.SessionImpl executing insertions
2005-06-21 20:34:03,800 [2572] INFO NHibernate.Impl.BatcherImpl Preparing INSERT INTO BALANCE_TBL (CD_DATE, BUS_DATE, FUND_ID, NAV_END_BAL, CRNCY_CD_LOC, CD_END_BAL, ACCOUNT, SUB_ACCOUNT, CRNCY_CD_FIN, CRNCY_CD_BASE, ACCOUNT_DESC) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10); select SCOPE_IDENTITY()
Success Log:
2005-06-21 20:41:32,959 [2760] INFO NHibernate.Impl.BatcherImpl Preparing INSERT INTO BALANCE_TBL (CD_DATE, BUS_DATE, FUND_ID, NAV_END_BAL, CRNCY_CD_LOC, CD_END_BAL, ACCOUNT, SUB_ACCOUNT, CRNCY_CD_FIN, CRNCY_CD_BASE, ACCOUNT_DESC, ID) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11)
CHW