Hi,
I'm running into issues mapping an object that has two bag properties
that are the inverse of each other. The object is a Task that has
Dependencies and Dependents (which are both lists of Tasks). If Task
A is a dependency of Task B, then Task B is a dependent of Task A.
Ideally, this relationship would only go in one direction, but my
application requires both. :(
The error I'm running into is that I can create a new Task and save it
with no problem. However, whenever I try to modify it, I get a
NullReferenceException while NHibernate tries to initialize a
collection. I've copied the stack trace and simplified mapping file
below. Is the mapping wrong for this type of relationship? If you
disassemble the code, the "ICollectionPersister persister" variable
being passed into InitializeCollectionFromCache is null, causing the
exception.
<class name="Task" table="task" discriminator-value="none">
<discriminator column="type" type="string" length="64" />
<bag name="Dependencies" table="TaskDependency">
<key column="taskId" />
<many-to-many column="dependencyId" class="BaseTask" />
</bag>
<bag name="Dependents" table="TaskDependency" inverse="true">
<key column="dependencyId" />
<many-to-many column="taskId" class="BaseTask" />
</bag>
<bag name="TaskProperties" table="taskProperty" cascade="all"
inverse="true">
<key column="taskId" />
<one-to-many class="TaskProperty" />
</bag>
<subclass name="TaskType1"
discriminator-value="type1"></subclass>
<subclass name="TaskType2"
discriminator-value="type2"></subclass>
</class>
</hibernate-mapping>
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="NHibernate"
StackTrace:
at
NHibernate.Event.Default.DefaultInitializeCollectionEventListener.InitializeCollectionFromCache
(Object id, ICollectionPersister persister, IPersistentCollection
collection, ISessionImplementor source)
at
NHibernate.Event.Default.DefaultInitializeCollectionEventListener.OnInitializeCollection
(InitializeCollectionEvent event)
at NHibernate.Impl.SessionImpl.InitializeCollection
(IPersistentCollection collection, Boolean writing)
at NHibernate.Collection.AbstractPersistentCollection.Initialize
(Boolean writing)
at NHibernate.Collection.AbstractPersistentCollection.Read()
at
NHibernate.Collection.Generic.PersistentGenericBag`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator
()
at
System.Collections.ObjectModel.ReadOnlyCollection`1.GetEnumerator()
at NHibernate.Collection.Generic.PersistentGenericBag`1.Snapshot
(ICollectionPersister persister)
at
NHibernate.Collection.AbstractPersistentCollection.GetSnapshot
(ICollectionPersister persister)
at NHibernate.Engine.CollectionEntry.AfterAction
(IPersistentCollection collection)
at NHibernate.Action.CollectionRecreateAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable
executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions
(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush
(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at ...MyRepository.SaveTask(ITask task)
at ...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---