Curious, I am finding similar issues in my parent-child, getting exceptions
"could not delete collection rows" and inner "null value in column of
relation violates not-null constraint", basically a child that SHOULD be
removed from the parent, then deleted from the databae... A common thing to
want to do IMO.
How does 'equality' have anything to do with that I wonder. Key take aways
from above, curious about comparing Type with GetActualType? Why? Except
perhaps there are proxies involved, but are these not base class the model?
And with pattern matching does that not also sort some of that concern?
i.e. 'obj is T instance' and so forth. Granted pattern matching was not
there probably with the OP. But now that it is...
Also the hash code, with the type foundation and its hash code as the
basis, that's interesting. Is that because Session is hashing 'all' objects
in a flat collection? I could see perhaps that there would be some
unintended collisions going on if one did not base it on the Type as well.
Best and thank you!
On Monday, October 25, 2010 at 3:54:18 AM UTC-4 Frank wrote:
> it seems that i found the problem...
> the override for Equals and GetHashCode causes this error.
>
> i changed my code and it works
>
> public override bool Equals(object obj)
> {
> var toCompare = obj as RefDruckUndVersandFilter;
>
> if (toCompare == null)
> return false;
>
> if (!GetType().Equals(toCompare.GetActualType()))
> return false;
>
> if (ReferenceEquals(this, toCompare))
> return true;
>
> return DruckUndVersand == toCompare.DruckUndVersand
> && Rank == toCompare.Rank
> //&&Filter == toCompare.Filter old causes the error
> ;
> }
>
> protected virtual Type GetActualType()
> {
> return GetType();
> }
>
> public override int GetHashCode()
> {
> unchecked
> {
> var hashcode = GetType().GetHashCode();
>
> hashcode = (hashcode * 31) ^ (DruckUndVersand !=
> null ? DruckUndVersand.GetHashCode() : 0);
> hashcode = (hashcode * 31) ^ Rank.GetHashCode();
> //hashcode = (hashcode * 31) ^ (Filter != null ?
> Filter .GetHashCode() : 0); old causes the error
>
> return hashcode;
> }
>
> }
>
> On 24 Okt., 14:59, Frank <[email protected]> wrote:
> > hi james, i have both situations.
> >
> > 1st: if i have a parent(DruckUndVersand) with
> > childs(RefDruckUndVersandFilter) and i call ISession.Delete(parent) i
> > get KeyNotFoundException.
> > 2nd: if i have a parent(DruckUndVersand) with
> > childs(RefDruckUndVersandFilter) and i remove some child from the
> > parent collection and call ISession.SaveOrUpdate(parent) i get
> > KeyNotFoundException too.
> >
> > somethin strange is that the generated sql would work... but commit
> > transaction give me the error.
> >
> > how should my HasMany look like? i'm really new to nhibernate at all
> >
> > below some additional information
> >
> > StackTrace
> >
> > bei System.Collections.Generic.Dictionary`2.get_Item(TKey key)
> > bei
> > NHibernate.Engine.StatefulPersistenceContext.RemoveEntity(EntityKey
> > key) in d:\CSharp\NH\nhibernate\src\NHibernate\Engine
> > \StatefulPersistenceContext.cs:Zeile 434.
> > bei NHibernate.Action.EntityDeleteAction.Execute() in d:\CSharp\NH
> > \nhibernate\src\NHibernate\Action\EntityDeleteAction.cs:Zeile 86.
> > bei NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in d:
> > \CSharp\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs:Zeile 130.
> > bei NHibernate.Engine.ActionQueue.ExecuteActions(IList list) in d:
> > \CSharp\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs:Zeile 113.
> > bei NHibernate.Engine.ActionQueue.ExecuteActions() in d:\CSharp\NH
> > \nhibernate\src\NHibernate\Engine\ActionQueue.cs:Zeile 151.
> > bei
> >
> NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IE
> ventSource
> > session) in d:\CSharp\NH\nhibernate\src\NHibernate\Event\Default
> > \AbstractFlushingEventListener.cs:Zeile 241.
> > bei
> > NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent
> > event) in d:\CSharp\NH\nhibernate\src\NHibernate\Event\Default
> > \DefaultFlushEventListener.cs:Zeile 19.
> > bei NHibernate.Impl.SessionImpl.Flush() in d:\CSharp\NH\nhibernate\src
> > \NHibernate\Impl\SessionImpl.cs:Zeile 1524.
> > bei NHibernate.Transaction.AdoTransaction.Commit() in d:\CSharp\NH
> > \nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:Zeile 187.
> > bei
> >
> LFF.Kabu.Win.Tabellenverwaltung.DataAccess.NHibernate.UnitOfWork.CommitTran
> saction()
> > in C:\Demos\Tabellenverwaltung\DataAccess.NHibernate
> > \UnitOfWork.cs:Zeile 77.
> > bei
> >
> LFF.Kabu.Win.TabModul.DruckUndVersand.ViewModel.DruckUndVersandVM.SaveData(
> )
> >
> > nhibernate log
> >
> > 15:15:09.249 [17] DEBUG NHibernate.Transaction.AdoTransaction - Begin
> > (ReadCommitted)
> > 15:15:09.249 [17] DEBUG NHibernate.Connection.DriverConnectionProvider
> > - Obtaining IDbConnection from Driver
> > 15:15:09.249 [17] DEBUG
> > NHibernate.Event.Default.DefaultDeleteEventListener - deleting a
> > persistent instance
> > 15:15:09.249 [17] DEBUG
> > NHibernate.Event.Default.DefaultDeleteEventListener - deleting
> > [LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand#9]
> > 15:15:09.249 [17] DEBUG NHibernate.Impl.SessionImpl - setting cache
> > mode to: Get
> > 15:15:09.249 [17] INFO NHibernate.Engine.Cascade - processing cascade
> > NHibernate.Engine.CascadingAction+DeleteCascadingAction for:
> > LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand
> > 15:15:09.249 [17] INFO NHibernate.Engine.Cascade - cascade
> > NHibernate.Engine.CascadingAction+DeleteCascadingAction for
> > collection:
> > LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.RefFilters
> > 15:15:09.264 [17] DEBUG NHibernate.Engine.CascadingAction - cascading
> > to delete:
> > LFF.Kabu.Win.Tabellenverwaltung.Entities.RefDruckUndVersandFilter
> > 15:15:09.264 [17] DEBUG
> > NHibernate.Event.Default.DefaultDeleteEventListener - deleting a
> > persistent instance
> > 15:15:09.264 [17] DEBUG
> > NHibernate.Event.Default.DefaultDeleteEventListener - deleting
> >
> [LFF.Kabu.Win.Tabellenverwaltung.Entities.RefDruckUndVersandFilter#LFF.Kabu
> .Win.Tabellenverwaltung.Entities.RefDruckUndVersandFilter]
> > 15:15:09.264 [17] DEBUG NHibernate.Impl.SessionImpl - setting cache
> > mode to: Get
> > 15:15:09.264 [17] DEBUG NHibernate.Impl.SessionImpl - setting cache
> > mode to: Get
> > 15:15:09.264 [17] DEBUG NHibernate.Impl.SessionImpl - setting cache
> > mode to: Get
> > 15:15:09.264 [17] DEBUG NHibernate.Impl.SessionImpl - setting cache
> > mode to: Get
> > 15:15:09.264 [17] INFO NHibernate.Engine.Cascade - done cascade
> > NHibernate.Engine.CascadingAction+DeleteCascadingAction for
> > collection:
> > LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.RefFilters
> > 15:15:09.264 [17] INFO NHibernate.Engine.Cascade - cascade
> > NHibernate.Engine.CascadingAction+DeleteCascadingAction for
> > collection:
> >
> LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.RefDruckUndVersand
> Ausgaben
> > 15:15:09.264 [17] DEBUG
> > NHibernate.Event.Default.DefaultInitializeCollectionEventListener -
> > initializing collection
> >
> [LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.RefDruckUndVersan
> dAusgaben#9]
> > 15:15:09.264 [17] DEBUG
> > NHibernate.Event.Default.DefaultInitializeCollectionEventListener -
> > checking second-level cache
> > 15:15:09.264 [17] DEBUG
> > NHibernate.Event.Default.DefaultInitializeCollectionEventListener -
> > collection not cached
> > 15:15:09.264 [17] DEBUG NHibernate.Loader.Loader - loading collection:
> >
> [LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.RefDruckUndVersan
> dAusgaben#9]
> > 15:15:09.264 [17] DEBUG NHibernate.AdoNet.AbstractBatcher - Opened new
> > IDbCommand, open IDbCommands: 1
> > 15:15:09.264 [17] DEBUG NHibernate.AdoNet.AbstractBatcher - Building
> > an IDbCommand object for the SqlString: SELECT
> > refdruckun0_.IDDruckUndVersand as IDDruckU1_1_, refdruckun0_.IDAUSGABE
> > as IDAUSGABE1_, refdruckun0_.IDDruckUndVersand as IDDruckU1_3_0_,
> > refdruckun0_.IDAUSGABE as IDAUSGABE3_0_,
> > refdruckun0_.OBAUTOMATISCHDRUCKEN as OBAUTOMA3_3_0_,
> > refdruckun0_.Druckerpfad as Druckerp4_3_0_, refdruckun0_.Beschreibung
> > as Beschrei5_3_0_ FROM REFDruckUndVersandAUSGABE refdruckun0_ WHERE
> > refdruckun0_.IDDruckUndVersand=?
> > 15:15:09.264 [17] DEBUG NHibernate.Engine.QueryParameters -
> > BindParameters(Positional0:NHibernate.Type.Int64Type) 9 -> [0]
> > 15:15:09.264 [17] DEBUG NHibernate.Type.Int64Type - binding '9' to
> > parameter: 0
> > 15:15:09.264 [17] INFO NHibernate.Loader.Loader - SELECT
> > refdruckun0_.IDDruckUndVersand as IDDruckU1_1_, refdruckun0_.IDAUSGABE
> > as IDAUSGABE1_, refdruckun0_.IDDruckUndVersand as IDDruckU1_3_0_,
> > refdruckun0_.IDAUSGABE as IDAUSGABE3_0_,
> > refdruckun0_.OBAUTOMATISCHDRUCKEN as OBAUTOMA3_3_0_,
> > refdruckun0_.Druckerpfad as Druckerp4_3_0_, refdruckun0_.Beschreibung
> > as Beschrei5_3_0_ FROM REFDruckUndVersandAUSGABE refdruckun0_ WHERE
> > refdruckun0_.IDDruckUndVersand=:p0
> > 15:15:09.264 [17] DEBUG NHibernate.SQL - SELECT
> > refdruckun0_.IDDruckUndVersand as IDDruckU1_1_, refdruckun0_.IDAUSGABE
> > as IDAUSGABE1_, refdruckun0_.IDDruckUndVersand as IDDruckU1_3_0_,
> > refdruckun0_.IDAUSGABE as IDAUSGABE3_0_,
> > refdruckun0_.OBAUTOMATISCHDRUCKEN as OBAUTOMA3_3_0_,
> > refdruckun0_.Druckerpfad as Druckerp4_3_0_, refdruckun0_.Beschreibung
> > as Beschrei5_3_0_ FROM REFDruckUndVersandAUSGABE refdruckun0_ WHERE
> > refdruckun0_.IDDruckUndVersand=:p0;:p0 = 9 [Type: Int64 (0)]
> > 15:15:09.264 [17] DEBUG NHibernate.Transaction.AdoTransaction - Enlist
> > Command
> > 15:15:09.264 [17] DEBUG NHibernate.AdoNet.AbstractBatcher -
> > ExecuteReader took 1 ms
> > 15:15:09.264 [17] DEBUG NHibernate.AdoNet.AbstractBatcher - Opened
> > IDataReader, open IDataReaders: 1
> > 15:15:09.264 [17] DEBUG NHibernate.Loader.Loader - result set contains
> > (possibly empty) collection:
> >
> [LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.RefDruckUndVersan
> dAusgaben#9]
> > 15:15:09.264 [17] DEBUG NHibernate.Engine.Loading.LoadContexts -
> > constructing collection load context for result set
> > [System.Data.OracleClient.OracleDataReader]
> > 15:15:09.264 [17] DEBUG
> > NHibernate.Engine.Loading.CollectionLoadContext - starting attempt to
> > find loading collection
> >
> [[LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.RefDruckUndVersa
> ndAusgaben#9]]
> > 15:15:09.264 [17] DEBUG NHibernate.Engine.Loading.LoadContexts -
> > attempting to locate loading collection entry
> >
> [CollectionKey[LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.Ref
> DruckUndVersandAusgaben#9]]
> > in any result-set context
> > 15:15:09.264 [17] DEBUG NHibernate.Engine.Loading.LoadContexts -
> > collection
> >
> [CollectionKey[LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.Ref
> DruckUndVersandAusgaben#9]]
> > located in load context
> > 15:15:09.264 [17] DEBUG
> > NHibernate.Engine.Loading.CollectionLoadContext - collection not yet
> > initialized; initializing
> > 15:15:09.264 [17] DEBUG NHibernate.Loader.Loader - processing result
> > set
> > 15:15:09.264 [17] DEBUG NHibernate.Loader.Loader - done processing
> > result set (0 rows)
> > 15:15:09.264 [17] DEBUG NHibernate.AdoNet.AbstractBatcher - Closed
> > IDataReader, open IDataReaders :0
> > 15:15:09.264 [17] DEBUG NHibernate.AdoNet.AbstractBatcher - DataReader
> > was closed after 2 ms
> > 15:15:09.264 [17] DEBUG NHibernate.AdoNet.AbstractBatcher - Closed
> > IDbCommand, open IDbCommands: 0
> > 15:15:09.264 [17] DEBUG NHibernate.Loader.Loader - total objects
> > hydrated: 0
> > 15:15:09.264 [17] DEBUG NHibernate.Engine.Loading.LoadContexts -
> > attempting to locate loading collection entry
> >
> [CollectionKey[LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.Ref
> DruckUndVersandAusgaben#9]]
> > in any result-set context
> > 15:15:09.264 [17] DEBUG NHibernate.Engine.Loading.LoadContexts -
> > collection
> >
> [CollectionKey[LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.Ref
> DruckUndVersandAusgaben#9]]
> > not located in load context
> > 15:15:09.264 [17] DEBUG
> > NHibernate.Engine.Loading.CollectionLoadContext - removing collection
> > load entry
> >
> [NHibernate.Engine.Loading.LoadingCollectionEntry<rs=System.Data.OracleClie
> nt.OracleDataReader,
> >
> coll=[LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.RefDruckUndV
> ersandAusgaben#9]>@69a2a7]
> > 15:15:09.264 [17] DEBUG
> > NHibernate.Engine.Loading.CollectionLoadContext - 1 collections were
> > found in result set for role:
> >
> LFF.Kabu.Win.Tabellenverwaltung.Entities.DruckUndVersand.RefDruckUndVersand
> Ausgaben
> > 15:15:09.264 [17] DEBUG
> > NHibernate.Engine.Loading.CollectionLoadContext - ending loading
> > collection ...
> >
> > Erfahren Sie mehr »
--
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/fluent-nhibernate/83e2684b-a94d-4f1e-94aa-68ac4e182bf9n%40googlegroups.com.