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.  [ 3 posts ] 
Author Message
 Post subject: 1.2 beta 2 cannot delete collection on cascade (MSSQL 2005)
PostPosted: Sat Jan 06, 2007 10:41 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
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]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 07, 2007 2:17 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
This is because you have all-delete-orphan set on the collection but (naturally) have not-null option on the column for KennelId. You'll need to change the cascade to 'all' to do this since what it will try to do is first snip the association between Kennel and Kennell.Contact (by setting NULL value in the KennelId column ) and then delete the Kennel.COntacts who are not associated with a parent (the 'orphan' bit).
Change your cascade and it'll work.

MIKE

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 07, 2007 11:50 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
That's a good thought, but I had already tried it with identical results. When I look at the objet graph pre-save, all of the relationships are set correctly as well. It's truly a mystery.


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