-->
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.  [ 1 post ] 
Author Message
 Post subject: Could someone refresh my understanding of cascade attribute?
PostPosted: Thu Jan 22, 2009 1:13 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.