Note, this was all working against SQL Server 2000 with 1.2 beta 1. I hadn't tested this particular feature against SQL Server 2005 with 1.2 beta 1 so I don't know if this is isolated to the DB or the code, although the outputted SQL leads me to suspect the library.... it's not even attempting to issue a delete to the contact table. Instead, it's attempting to update the contact table to set the kennelid to null.
Error:
Code:
Cannot insert the value NULL into column 'kennelId', table 'mobyWeb.dbo.Contact'; column does not allow nulls. UPDATE fails.
The statement has been terminated.
[SqlException (0x80131904): Cannot insert the value NULL into column 'kennelId', table 'mobyWeb.dbo.Contact'; column does not allow nulls. UPDATE fails.
The statement has been terminated.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857386
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734998
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +149
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +415
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd) +50
NHibernate.Persister.Collection.AbstractCollectionPersister.Remove(Object id, ISessionImplementor session) +604
[ADOException: could not delete collection: [KennelFinder.Kennel.Contacts#11962]]
NHibernate.Persister.Collection.AbstractCollectionPersister.Remove(Object id, ISessionImplementor session) +821
NHibernate.Impl.ScheduledCollectionUpdate.Execute() +200
NHibernate.Impl.SessionImpl.Execute(IExecutable executable) +169
NHibernate.Impl.SessionImpl.ExecuteAll(IList list) +124
NHibernate.Impl.SessionImpl.Execute() +261
NHibernate.Impl.SessionImpl.Flush() +112
NHibernate.Transaction.AdoTransaction.Commit() +131
KennelFinder.DbSessionContext.CommitTransaction() in C:\MobysThinkTank\KennelFinder\src\KennelFinder\DbSessionContext.cs:221
KennelFinder.DbSessionContext.Save(Object o) in C:\MobysThinkTank\KennelFinder\src\KennelFinder\DbSessionContext.cs:108
KennelFinder.KennelDataAccess.Save(Kennel kennel) in C:\MobysThinkTank\KennelFinder\src\KennelFinder\KennelDataAccess.cs:62
KennelFinder.Kennel.Save() in C:\MobysThinkTank\KennelFinder\src\KennelFinder\Kennel.cs:281
KennelFinder.Web.Administration.ManageKennel.SaveButton_Click(Object sender, EventArgs e) in C:\MobysThinkTank\KennelFinder\src\KennelFinder.Web\Administration\ManageKennel.aspx.cs:141
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Relevant part of Kennel.hbm.xml
Code:
<bag name="Contacts" lazy="true" cascade="all-delete-orphan" generic="true" inverse="false">
<key column="kennelId"></key>
<one-to-many class="KennelFinder.Contact, KennelFinder" />
</bag>
Contact.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="KennelFinder.Contact, KennelFinder" table="Contact" lazy="false">
<id name="Id" type="Int32" unsaved-value="0" access="nosetter.camelcase">
<column name="ContactId" not-null="true" unique="true" />
<generator class="identity" />
</id>
<property name="Value" column="contactText"/>
<property name="Description" column="description"/>
<many-to-one name="Type" column="contactTypeId" cascade="none" class="KennelFinder.ContactType, KennelFinder" />
<many-to-one name="Kennel" column="kennelId" cascade="none" class="KennelFinder.Kennel, KennelFinder" />
</class>
</hibernate-mapping>
Code:
Code:
Kennel.Contacts.Clear();
Kennel.Save();
From Kennel.Save:
Code:
DbSessionContext.Current.Save(kennel);
DbSessonContext.Current.Save:
Code:
public void Save(object o)
{
BeginTransaction();
try
{
Session.SaveOrUpdate(o);
CommitTransaction();
}
catch
{
RollbackTransaction();
throw;
}
}
Config:
Code:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="KennelFinder">
<property name="hibernate.dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="hibernate.connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="hibernate.connection.connection_string">Server=(local);initial catalog=mobyweb;Trusted_Connection=true;</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="hibernate.connection.isolation">ReadCommitted</property>
<property name="hibernate.use_proxy_validator">false</property>
<property name="hibernate.default_schema">mobyWeb.dbo</property>
<mapping assembly="KennelFinder"/>
</session-factory>
</hibernate-configuration>
[/quote]