-->
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.  [ 3 posts ] 
Author Message
 Post subject: Collections not being lazy loaded
PostPosted: Mon Jun 13, 2005 5:01 pm 
Regular
Regular

Joined: Fri May 13, 2005 4:08 pm
Posts: 64
I've seen a few posts on this already, but their problems and solutions don't seem to work, so any attention you can give to this post would be greatly appreciated!

I have been doing the nhRegistration tutorial for NHibernate with departments, classes, professors and students. But lazy-loading is obviously not working for me. I base this on asking NHibernate for just the Department entity, and I watch as the db server gets hit several times for all related entities, and after the session disconnects, all the related entities are reachable although I did not ask for them during the session.

I'll include all I think relevant below. Thanks again for reading and giving your tips! I'll be happy to send you the .zip of the solution if that would be helpful.

Department.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="nhRegistration.Department, nhRegistration" table="department">
      <id name="Id" column="deptid" unsaved-value="0">
         <generator class="native"/>
      </id>
      <property name="Name" column="deptname"/>
      <set name="Classes" cascade="all">
         <key column="deptid"/>
         <one-to-many class="nhRegistration.UniversityClass, nhRegistration"/>
      </set>
      <set name="Professors" table="departmentprofessor" cascade="all" lazy="false">
         <key column="deptid"/>
         <many-to-many column="personid" class="nhRegistration.Person, nhRegistration"/>
      </set>
   </class>
</hibernate-mapping>


Person.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="nhRegistration.Person, nhRegistration" table="person">
      <id name="Id" column="personid" unsaved-value="0">
         <generator class="native"/>
      </id>
      <discriminator column="persontype" type="String"/>
      <property name="FirstName" column="firstname"/>
      <property name="LastName" column="lastname"/>
      
      <subclass name="nhRegistration.Professor, nhRegistration" discriminator-value="professor">
         <property name="Identifier" column="identifier"/>
         <set name="Departments" table="departmentprofessor" inverse="true" cascade="all">
            <key column="personid"/>
            <many-to-many column="deptid" class="nhRegistration.Department, nhRegistration"/>
         </set>
         <set name="Classes" cascade="all">
            <key column="personid"/>
            <one-to-many class="nhRegistration.UniversityClass, nhRegistration"/>
         </set>
      </subclass>
      
      <subclass name="nhRegistration.Student, nhRegistration" discriminator-value="student">
         <property name="SSN" column="identifier"/>
         <set name="Classes" table="studentclass" cascade="all">
            <key column="personid"/>
            <many-to-many column="classid" class="nhRegistration.UniversityClass, nhRegistration"/>
         </set>
      </subclass>
   </class>
</hibernate-mapping>


Inside Department.cs
Code:
      private ISet professors;
      public ISet Professors
      {
         get
         {
            if (professors == null) professors = new ListSet();
            return professors;
         }
         set
         {
            professors = value;
         }
      }



unit test:
Code:
      [TestMethod()]
      public void LazyLoadingTest()
      {
         RegMgr mgr = (RegMgr)this.mgr;

         Department d = new Department();
         Professor p1 = new Professor();
         p1.FirstName = "Jack";
         Professor p2 = new Professor();
         p2.FirstName = "Jill";
         d.Professors.Add(p1);
         d.Professors.Add(p2);
         mgr.saveDepartment(d);

         mgr.workSession(delegate(NHibernate.ISession session)
         {
            d = (Department)session.CreateCriteria(typeof(Department)).List()[0];
            Assert.AreEqual(2, d.Professors.Count);
            return null;
         });

         mgr.workSession(delegate(NHibernate.ISession session)
         {
            d = (Department)session.Get(typeof(Department), d.Id);
            return null;
         });

         // assume that since the session is now disconnected, the
         // classes ought not to be reachable.
         Assert.AreEqual(0, d.Professors.Count); // this still returns 2!
         foreach (Professor p in d.Professors)  // and this still works!
            Assert.IsNotNull(p);
      }


workSession method:
Code:
      public object workSession(sessionClosure closure)
      {
         ISession session = null;
         ITransaction tx = null;
         try
         {
            session = factory.OpenSession();
            tx = session.BeginTransaction();

            object result = closure(session);

            tx.Commit();
            return result;
         }
         catch
         {
            if (tx != null) tx.Rollback();
            throw;
         }
         finally
         {
            if (session != null) session.Close();
         }
      }


And lastly, the log4net INFO output:
Code:
...
create table departmentprofessor (
  personid INT not null,
   deptid INT null
)
create table studentclass (
  personid INT not null,
   classid INT null
)
create table person (
  personid INT IDENTITY NOT NULL,
   persontype NVARCHAR(255) not null,
   firstname NVARCHAR(255) null,
   lastname NVARCHAR(255) null,
   identifier NVARCHAR(255) null,
   primary key (personid)
)
create table universityclass (
  classid INT IDENTITY NOT NULL,
   classname NVARCHAR(255) null,
   classnumber NVARCHAR(255) null,
   startdate DATETIME null,
   syllabus NVARCHAR(255) null,
   deptid INT null,
   personid INT null,
   primary key (classid)
)
create table department (
  deptid INT IDENTITY NOT NULL,
   deptname NVARCHAR(255) null,
   primary key (deptid)
)
alter table departmentprofessor  add constraint FK7965F81CBBA7E943 foreign key (deptid) references department
alter table departmentprofessor  add constraint FK7965F81C410FB78C foreign key (personid) references person
alter table studentclass  add constraint FK8FFC6493AE94E5C1 foreign key (classid) references universityclass
alter table studentclass  add constraint FK8FFC6493410FB78C foreign key (personid) references person
alter table universityclass  add constraint FKB201D856410FB78C foreign key (personid) references person
alter table universityclass  add constraint FKB201D856BBA7E943 foreign key (deptid) references department
2005-06-13 14:50:50,084ate [TestCasemanager::ExecutionThreadhread] NHibernate.Connection.ConnectionProvider.CloseConnection(:0)evel NHibernate.Connection.ConnectionProvider.CloseConnection(:0)ogger [DEBUGroperty{NDC}] - Closing connectionessage
ewline2005-06-13 14:50:50,084ate [TestCasemanager::ExecutionThreadhread] NHibernate.Connection.ConnectionProvider.Dispose(:0)evel NHibernate.Connection.ConnectionProvider.Dispose(:0)ogger [DEBUGroperty{NDC}] - Disposing of ConnectionProvider.essage
ewline2005-06-13 14:50:50,193ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.SessionImpl..ctor(:0)evel NHibernate.Impl.SessionImpl..ctor(:0)ogger [DEBUGroperty{NDC}] - opened sessionessage
ewline2005-06-13 14:50:50,209ate [TestCasemanager::ExecutionThreadhread] NHibernate.Transaction.AdoTransaction.Begin(:0)evel NHibernate.Transaction.AdoTransaction.Begin(:0)ogger [DEBUGroperty{NDC}] - beginessage
ewline2005-06-13 14:50:50,209ate [TestCasemanager::ExecutionThreadhread] NHibernate.Connection.DriverConnectionProvider.GetConnection(:0)evel NHibernate.Connection.DriverConnectionProvider.GetConnection(:0)ogger [DEBUGroperty{NDC}] - Obtaining IDbConnection from Driveressage
ewline2005-06-13 14:50:50,225ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades+IdentifierValue.IsUnsaved(:0)evel NHibernate.Engine.Cascades+IdentifierValue.IsUnsaved(:0)ogger [DEBUGroperty{NDC}] - unsaved-value: 0essage
ewline2005-06-13 14:50:50,225ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.SessionImpl.SaveOrUpdate(:0)evel NHibernate.Impl.SessionImpl.SaveOrUpdate(:0)ogger [DEBUGroperty{NDC}] - SaveOrUpdate() unsaved instanceessage
ewline2005-06-13 14:50:50,240ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.SessionImpl.ExecuteInserts(:0)evel NHibernate.Impl.SessionImpl.ExecuteInserts(:0)ogger [INFOroperty{NDC}] - executing insertionsessage
ewline2005-06-13 14:50:50,240ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - processing cascades for: nhRegistration.Departmentessage
ewline2005-06-13 14:50:50,256ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - done processing cascades for: nhRegistration.Departmentessage
ewline2005-06-13 14:50:50,256ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)evel NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)ogger [DEBUGroperty{NDC}] - Wrapped collection in role: nhRegistration.Department.Classesessage
ewline2005-06-13 14:50:50,256ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)evel NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)ogger [DEBUGroperty{NDC}] - Wrapped collection in role: nhRegistration.Department.Professorsessage
ewline2005-06-13 14:50:50,272ate [TestCasemanager::ExecutionThreadhread] NHibernate.Persister.EntityPersister.Insert(:0)evel NHibernate.Persister.EntityPersister.Insert(:0)ogger [DEBUGroperty{NDC}] - Inserting entity: nhRegistration.Department (native id)essage
ewline2005-06-13 14:50:50,272ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.LogOpenPreparedCommand(:0)evel NHibernate.Impl.BatcherImpl.LogOpenPreparedCommand(:0)ogger [DEBUGroperty{NDC}] - about to open: 0 open IDbCommands, 0 open DataReadersessage
ewline2005-06-13 14:50:50,303ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.Generate(:0)evel NHibernate.Impl.BatcherImpl.Generate(:0)ogger [DEBUGroperty{NDC}] - Building an IDbCommand object for the SqlString: INSERT INTO department (deptname) VALUES (:deptname); select SCOPE_IDENTITY()essage
ewline2005-06-13 14:50:50,318ate [TestCasemanager::ExecutionThreadhread] NHibernate.Persister.EntityPersister.Dehydrate(:0)evel NHibernate.Persister.EntityPersister.Dehydrate(:0)ogger [DEBUGroperty{NDC}] - Dehydrating entity: nhRegistration.Department#essage
ewline2005-06-13 14:50:50,318ate [TestCasemanager::ExecutionThreadhread] NHibernate.Type.NullableType.NullSafeSet(:0)evel NHibernate.Type.NullableType.NullSafeSet(:0)ogger [DEBUGroperty{NDC}] - binding null to parameter: 0essage
ewline2005-06-13 14:50:50,318ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.Prepare(:0)evel NHibernate.Impl.BatcherImpl.Prepare(:0)ogger [INFOroperty{NDC}] - Preparing INSERT INTO department (deptname) VALUES (@p0); select SCOPE_IDENTITY()essage
ewline2005-06-13 14:50:50,412ate [TestCasemanager::ExecutionThreadhread] NHibernate.Persister.EntityPersister.Insert(:0)evel NHibernate.Persister.EntityPersister.Insert(:0)ogger [DEBUGroperty{NDC}] - Natively generated identity: 1essage
ewline2005-06-13 14:50:50,412ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.LogClosePreparedCommand(:0)evel NHibernate.Impl.BatcherImpl.LogClosePreparedCommand(:0)ogger [DEBUGroperty{NDC}] - done closing: 0 open IDbCommands, 0 open DataReadersessage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - processing cascades for: nhRegistration.Departmentessage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.CascadeCollection(:0)evel NHibernate.Engine.Cascades.CascadeCollection(:0)ogger [DEBUGroperty{NDC}] - cascading to collection: nhRegistration.Department.Classesessage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.CascadeCollection(:0)evel NHibernate.Engine.Cascades.CascadeCollection(:0)ogger [DEBUGroperty{NDC}] - cascading to collection: nhRegistration.Department.Professorsessage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass.Cascade(:0)evel NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass.Cascade(:0)ogger [DEBUGroperty{NDC}] - cascading to SaveOrUpdate()essage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades+IdentifierValue.IsUnsaved(:0)evel NHibernate.Engine.Cascades+IdentifierValue.IsUnsaved(:0)ogger [DEBUGroperty{NDC}] - unsaved-value: 0essage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.SessionImpl.SaveOrUpdate(:0)evel NHibernate.Impl.SessionImpl.SaveOrUpdate(:0)ogger [DEBUGroperty{NDC}] - SaveOrUpdate() unsaved instanceessage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.SessionImpl.ExecuteInserts(:0)evel NHibernate.Impl.SessionImpl.ExecuteInserts(:0)ogger [INFOroperty{NDC}] - executing insertionsessage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - processing cascades for: nhRegistration.Professoressage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - done processing cascades for: nhRegistration.Professoressage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)evel NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)ogger [DEBUGroperty{NDC}] - Wrapped collection in role: nhRegistration.Professor.Classesessage
ewline2005-06-13 14:50:50,428ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)evel NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)ogger [DEBUGroperty{NDC}] - Wrapped collection in role: nhRegistration.Professor.Departmentsessage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Persister.EntityPersister.Insert(:0)evel NHibernate.Persister.EntityPersister.Insert(:0)ogger [DEBUGroperty{NDC}] - Inserting entity: nhRegistration.Professor (native id)essage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.LogOpenPreparedCommand(:0)evel NHibernate.Impl.BatcherImpl.LogOpenPreparedCommand(:0)ogger [DEBUGroperty{NDC}] - about to open: 0 open IDbCommands, 0 open DataReadersessage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.Generate(:0)evel NHibernate.Impl.BatcherImpl.Generate(:0)ogger [DEBUGroperty{NDC}] - Building an IDbCommand object for the SqlString: INSERT INTO person (identifier, lastname, firstname, persontype) VALUES (:identifier, :lastname, :firstname, 'professor'); select SCOPE_IDENTITY()essage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Persister.EntityPersister.Dehydrate(:0)evel NHibernate.Persister.EntityPersister.Dehydrate(:0)ogger [DEBUGroperty{NDC}] - Dehydrating entity: nhRegistration.Professor#essage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Type.NullableType.NullSafeSet(:0)evel NHibernate.Type.NullableType.NullSafeSet(:0)ogger [DEBUGroperty{NDC}] - binding null to parameter: 0essage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Type.NullableType.NullSafeSet(:0)evel NHibernate.Type.NullableType.NullSafeSet(:0)ogger [DEBUGroperty{NDC}] - binding null to parameter: 1essage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Type.NullableType.NullSafeSet(:0)evel NHibernate.Type.NullableType.NullSafeSet(:0)ogger [DEBUGroperty{NDC}] - binding 'Jack' to parameter: 2essage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.Prepare(:0)evel NHibernate.Impl.BatcherImpl.Prepare(:0)ogger [INFOroperty{NDC}] - Preparing INSERT INTO person (identifier, lastname, firstname, persontype) VALUES (@p0, @p1, @p2, 'professor'); select SCOPE_IDENTITY()essage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Persister.EntityPersister.Insert(:0)evel NHibernate.Persister.EntityPersister.Insert(:0)ogger [DEBUGroperty{NDC}] - Natively generated identity: 1essage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.LogClosePreparedCommand(:0)evel NHibernate.Impl.BatcherImpl.LogClosePreparedCommand(:0)ogger [DEBUGroperty{NDC}] - done closing: 0 open IDbCommands, 0 open DataReadersessage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - processing cascades for: nhRegistration.Professoressage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.CascadeCollection(:0)evel NHibernate.Engine.Cascades.CascadeCollection(:0)ogger [DEBUGroperty{NDC}] - cascading to collection: nhRegistration.Professor.Classesessage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.CascadeCollection(:0)evel NHibernate.Engine.Cascades.CascadeCollection(:0)ogger [DEBUGroperty{NDC}] - cascading to collection: nhRegistration.Professor.Departmentsessage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - done processing cascades for: nhRegistration.Professoressage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass.Cascade(:0)evel NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass.Cascade(:0)ogger [DEBUGroperty{NDC}] - cascading to SaveOrUpdate()essage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades+IdentifierValue.IsUnsaved(:0)evel NHibernate.Engine.Cascades+IdentifierValue.IsUnsaved(:0)ogger [DEBUGroperty{NDC}] - unsaved-value: 0essage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.SessionImpl.SaveOrUpdate(:0)evel NHibernate.Impl.SessionImpl.SaveOrUpdate(:0)ogger [DEBUGroperty{NDC}] - SaveOrUpdate() unsaved instanceessage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.SessionImpl.ExecuteInserts(:0)evel NHibernate.Impl.SessionImpl.ExecuteInserts(:0)ogger [INFOroperty{NDC}] - executing insertionsessage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - processing cascades for: nhRegistration.Professoressage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - done processing cascades for: nhRegistration.Professoressage
ewline2005-06-13 14:50:50,443ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)evel NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)ogger [DEBUGroperty{NDC}] - Wrapped collection in role: nhRegistration.Professor.Classesessage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)evel NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(:0)ogger [DEBUGroperty{NDC}] - Wrapped collection in role: nhRegistration.Professor.Departmentsessage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Persister.EntityPersister.Insert(:0)evel NHibernate.Persister.EntityPersister.Insert(:0)ogger [DEBUGroperty{NDC}] - Inserting entity: nhRegistration.Professor (native id)essage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.LogOpenPreparedCommand(:0)evel NHibernate.Impl.BatcherImpl.LogOpenPreparedCommand(:0)ogger [DEBUGroperty{NDC}] - about to open: 0 open IDbCommands, 0 open DataReadersessage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.Generate(:0)evel NHibernate.Impl.BatcherImpl.Generate(:0)ogger [DEBUGroperty{NDC}] - Using prebuilt IDbCommand object for the SqlString: INSERT INTO person (identifier, lastname, firstname, persontype) VALUES (:identifier, :lastname, :firstname, 'professor'); select SCOPE_IDENTITY()essage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Persister.EntityPersister.Dehydrate(:0)evel NHibernate.Persister.EntityPersister.Dehydrate(:0)ogger [DEBUGroperty{NDC}] - Dehydrating entity: nhRegistration.Professor#essage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Type.NullableType.NullSafeSet(:0)evel NHibernate.Type.NullableType.NullSafeSet(:0)ogger [DEBUGroperty{NDC}] - binding null to parameter: 0essage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Type.NullableType.NullSafeSet(:0)evel NHibernate.Type.NullableType.NullSafeSet(:0)ogger [DEBUGroperty{NDC}] - binding null to parameter: 1essage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Type.NullableType.NullSafeSet(:0)evel NHibernate.Type.NullableType.NullSafeSet(:0)ogger [DEBUGroperty{NDC}] - binding 'Jill' to parameter: 2essage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.Prepare(:0)evel NHibernate.Impl.BatcherImpl.Prepare(:0)ogger [INFOroperty{NDC}] - Preparing INSERT INTO person (identifier, lastname, firstname, persontype) VALUES (@p0, @p1, @p2, 'professor'); select SCOPE_IDENTITY()essage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Persister.EntityPersister.Insert(:0)evel NHibernate.Persister.EntityPersister.Insert(:0)ogger [DEBUGroperty{NDC}] - Natively generated identity: 2essage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.BatcherImpl.LogClosePreparedCommand(:0)evel NHibernate.Impl.BatcherImpl.LogClosePreparedCommand(:0)ogger [DEBUGroperty{NDC}] - done closing: 0 open IDbCommands, 0 open DataReadersessage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - processing cascades for: nhRegistration.Professoressage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.CascadeCollection(:0)evel NHibernate.Engine.Cascades.CascadeCollection(:0)ogger [DEBUGroperty{NDC}] - cascading to collection: nhRegistration.Professor.Classesessage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.CascadeCollection(:0)evel NHibernate.Engine.Cascades.CascadeCollection(:0)ogger [DEBUGroperty{NDC}] - cascading to collection: nhRegistration.Professor.Departmentsessage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - done processing cascades for: nhRegistration.Professoressage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - done processing cascades for: nhRegistration.Departmentessage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Transaction.AdoTransaction.Commit(:0)evel NHibernate.Transaction.AdoTransaction.Commit(:0)ogger [DEBUGroperty{NDC}] - commitessage
ewline2005-06-13 14:50:50,459ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.SessionImpl.FlushEverything(:0)evel NHibernate.Impl.SessionImpl.FlushEverything(:0)ogger [DEBUGroperty{NDC}] - flushing sessionessage
ewline2005-06-13 14:50:50,475ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.Cascade(:0)evel NHibernate.Engine.Cascades.Cascade(:0)ogger [DEBUGroperty{NDC}] - processing cascades for: nhRegistration.Departmentessage
ewline2005-06-13 14:50:50,475ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.CascadeCollection(:0)evel NHibernate.Engine.Cascades.CascadeCollection(:0)ogger [DEBUGroperty{NDC}] - cascading to collection: nhRegistration.Department.Classesessage
ewline2005-06-13 14:50:50,475ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades.CascadeCollection(:0)evel NHibernate.Engine.Cascades.CascadeCollection(:0)ogger [DEBUGroperty{NDC}] - cascading to collection: nhRegistration.Department.Professorsessage
ewline2005-06-13 14:50:50,475ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass.Cascade(:0)evel NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass.Cascade(:0)ogger [DEBUGroperty{NDC}] - cascading to SaveOrUpdate()essage
ewline2005-06-13 14:50:50,475ate [TestCasemanager::ExecutionThreadhread] NHibernate.Impl.SessionImpl.SaveOrUpdate(:0)evel NHibernate.Impl.SessionImpl.SaveOrUpdate(:0)ogger [DEBUGroperty{NDC}] - SaveOrUpdate() persistent instanceessage
ewline2005-06-13 14:50:50,475ate [TestCasemanager::ExecutionThreadhread] NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass.Cascade(:0)evel N


Top
 Profile  
 
 Post subject: Re: Collections not being lazy loaded
PostPosted: Tue Jun 14, 2005 2:15 am 
I answer my own question:

aarnott wrote:
Department.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="nhRegistration.Department, nhRegistration" table="department">
      <id name="Id" column="deptid" unsaved-value="0">
         <generator class="native"/>
      </id>
      <property name="Name" column="deptname"/>
      <set name="Classes" cascade="all">
         <key column="deptid"/>
         <one-to-many class="nhRegistration.UniversityClass, nhRegistration"/>
      </set>
      <set name="Professors" table="departmentprofessor" cascade="all" lazy="false">
         <key column="deptid"/>
         <many-to-many column="personid" class="nhRegistration.Person, nhRegistration"/>
      </set>
   </class>
</hibernate-mapping>



First, I actually had lazy="false" in the above snippets because I copied a poor version of the file I had had. I was trying all sorts of things to make it work. I meant to have lazy="true".

It turns out that lazy="true", together with a little bug fix that I had elsewhere in the mapping document, did the trick. I was going off of Hibernate 3.0's documentation which said that lazy loading was enabled by default. Apparently with NHibernate it is not. lazy='true' must be explicitly set in order to enable lazy loading, which I did not know.


Top
  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 11:29 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Right, the default for Hibernate 2 which NHibernate is based on is to use lazy="false". Don't use Hibernate 3 documentation, use Hibernate 2.1


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

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.