I am working on an application that uses NHibernate 3.1.0 and builds a
large object graph of results (new unsaved transient objects), but,
depending on the status of the process, needs to exclude some of the
results from persistence. The method the application currently uses
to prevent persistence of new unsaved objects is to orphan them and
rely on garbage collection to clean them up. This works fine when
cascading all, but does not work when cascading all-delete-orphan.
In the GetOrphans method of AbstractPersistentCollection I noticed
that the gathering of the currentIds filters out transient objects:
if (current != null && ForeignKeys.IsNotTransient(entityName,
current, null, session))
but there is no corresponding filter when iterating over the old list
before the call to GetEntityIdentifierIfNotUnsaved and
GetEntityIdentifierIfNotUnsaved method will throw an exception if the
object does not have an identifier and is transient. We derive our
identifiers from identity column in the database (I understand that
this is not recommended practice, but the database for this
application was architected before adopting NHibernate) so we have to
persist to the database before orphaning the object in order for
cascade all-delete-orphan.
Is it necessary for GetOrphans to include evaluation of transient
objects for the old list? I'm wondering why currentIds only includes
non-transient objects, but the old list does not include the same
restriction.
Regards,
David Slayton