I thought I had set a collection to prevent cascading, however, when I flush my session, I think I'm seeing evidence in the debug logs of NH cascading SaveOrUpdate() to the collection that should not be "cascaded." I might tend to ignore this since there is never anything to save with this object graph, but it is unnecessary overhead and I am seeing some performance issues I'd like to resolve. (BTW, I can't just make these immutable...)
I have the abstract class (AbstractSurvey) set to cascade="none" for its Questions collection (AbstractQuestion). Now, when I flush the session, I see the SaveOrUpdate being passed to the concrete survey objects in the cache, which is fine, but the cascade is sent along to its concrete questions collection which fires off all the way down the object graph which is like seven levels deep. Anyone care to explain why? I must be doing something wrong here, but I can't figure it out...
-devon
Hibernate version: 1.2.1 (.NET 2.0)
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2" default-lazy="false"
assembly="Abundance.Core"
namespace="Abundance.Core.Domain.Surveys">
<class
name="AbstractSurvey"
table="Survey"
dynamic-insert="true"
dynamic-update="true">
<cache usage="read-write" />
<id
name="id"
column="SurveyID"
type="Int32"
unsaved-value="-1"
access="field">
<generator class="identity" />
</id>
<version
name="version"
column="Version"
type="Int32"
unsaved-value="-1"
access="field" />
...
<bag
name="Questions"
inverse="true"
cascade="none"
lazy="false"
where="DisplayOrder IS NOT NULL"
order-by="DisplayOrder"
access="nosetter.camelcase">
<cache usage="read-write" />
<key column="SurveyID" />
<one-to-many class="AbstractQuestion" />
</bag>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2" default-lazy="false"
assembly="Abundance.Core"
namespace="Abundance.Core.Domain.Surveys">
<class
name="AbstractQuestion"
table="SurveyQuestion"
dynamic-insert="true"
dynamic-update="true">
<cache usage="read-write" />
<id
name="id"
column="QuestionID"
type="Int32"
unsaved-value="-1"
access="field">
<generator class="identity" />
</id>
<version
name="version"
column="Version"
type="Int32"
unsaved-value="-1"
access="field" />
...
<many-to-one
name="Survey"
column="SurveyID"
class="AbstractSurvey"
update="false"
cascade="none"
access="nosetter.camelcase" />
<bag
name="Answers"
inverse="true"
cascade="delete-orphan"
order-by="DisplayOrder"
lazy="false"
access="nosetter.camelcase">
<cache usage="read-write" />
<key column="QuestionID" />
<one-to-many class="AbstractAnswer" />
</bag>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():There is too much code here, but the effect I'm seeing occurs when I flush the session and commit the transaction on Session_End like so:
Code:
public void CloseSession()
{
ISession session = (ISession) this.ContextSession;
if (session != null && session.IsOpen)
{
log.Debug("Flushing Session: " + session.GetHashCode());
session.Flush();
log.Debug("Closing Session: " + session.GetHashCode());
session.Close();
}
this.ContextSession = null;
}
Debug level Hibernate log excerpt:Code:
2009-01-21 16:13:58,403 [7] DEBUG Abundance.Data.Service.SessionManager - Flushing Session: 3893639
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Member
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Member.Memberships
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Member.Roles
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Member
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Role
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Role.Members
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Role
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Role
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Role.Members
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Role
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Role
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Role.Members
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Role
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Role
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Role.Members
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Role
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Role
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Role.Members
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Role
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Member
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Member.Memberships
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Member.Roles
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Member
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Surveys.PersonalValues.ValuesSurvey
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Surveys.PersonalValues.ValuesSurvey
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementSurvey
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementSurvey
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Surveys.GroupMissionStatement.GroupMissionStatementQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Surveys.PersonalValues.ValuesQuestion
2009-01-21 16:13:58,403 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Surveys.PersonalValues.ValuesQuestion
... and so on down the line for each concrete survey and its collection of questions and the graphs below this collection
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Surveys.WealthPriorities.ImpactQuestion
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Surveys.WealthPriorities.ImpactQuestion
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Company
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Company.Administrators
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Company
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - processing cascades for: Abundance.Core.Domain.Group
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - cascading to collection: Abundance.Core.Domain.Group.Memberships
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - cascading to SaveOrUpdate()
2009-01-21 16:13:58,434 [7] DEBUG NHibernate.Engine.Cascades - done processing cascades for: Abundance.Core.Domain.Group
... some more flushing and cascading that I expect, and then we're done.
2009-01-21 16:13:58,512 [7] DEBUG Abundance.Data.Service.SessionManager - Closing Session: 3893639