Hi All,

I have a specific problem with respect to using Lazy Loading Proxies.

I have mapped a class hierarchy for a CMS system that I am building.
The hierarchy is as follows:

IContentNode
        ContentNodeCommonBase (implements IContentNode)
                Site (inherits ContentNodeCommonBase)
                ContentNodeNavigableBase (inherits
ContentNodeCommonBase)
                        Content (inherits ContentNodeNavigableBase)

I have simplified the problem down to a few fields:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHTest" namespace="NHTest">

    <class name="IContentNode" table="contentnodes">
          <id name="Guid" type="Guid" column="Guid">
              <generator class="guid.comb" />
          </id>
          <discriminator column="ContentType" />
          <subclass name="ContentNodeCommonBase">
              <many-to-one name="Parent" class="IContentNode" />
              <many-to-one name="SiteField" class="Site"
access="field" />

              <set name="ChildNodesField" cascade="all" access="field"
inverse="true">
                  <key column="Parent" />
                  <one-to-many class="IContentNode" />
              </set>

              <subclass name="Site" />

              <subclass name="ContentNodeNavigableBase">
                  <subclass name="Content" />
              </subclass>
          </subclass>
    </class>


There are more properties, but this mapping is enough to reveal my
problem.

I then export the schema, and NHibernate creates a perfectly logical
database layout.

For test data, I create a "Site", and a "Content" added as a child of
the Site object, I also set the Parent reference of the Content to
point back to the Site.

When I save the site using ISession.Save, NHibernate saves my Site,
and my Content, and all the Parent pointers are set up correctly, and
it all works, but the problem is in retrieval.


If I take the Guid of my Content and do a:

dim c as Content = s.CreateCriteria(Of
IContentNode).Add(expression.eq("Guid",
contentguid)).SetMaxResults(1).UniqueResult()

This results in a "Cannot create proxy" exception. What's going on? It
saves, but can't retrieve!


After poking about a bit, I added lazy="false" to my Parent and Site
References, and it starts working. This means that I can continue
unhindered, but this means that if my tree hierarchy is 30 levels
deep, NHibernate would clearly load all 30 levels during a read of the
leaf node.


What I want to know is, A) what's going on? B) how can I fix it so
that I get to choose whether it uses Lazy Proxies or immediate fetch?



As a little more info, if I open my session, then load all data rows
into a list (which works), I find that my proxies Parent and Site
properties point back at the same object i.e. this.Parent == this,
hmm.

Also, if I've done a load of the entire list, the above query then
appears to work (from the cache?), but again, the Parent proxies are
pointing at the wrong object.

Again, What's going on? What's the Solution?


If anyone has any general advice (because I'm a NHibernate newbie), it
would be gladly received.


Thanks,

Mark

-- 
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.

Reply via email to