Hi,
I'm cross-posting my question I just put up on StackOverflow...
(
http://stackoverflow.com/questions/2059051/nhibernate-not-loading-third-level-properties-lazy-loading-strategy-or-non-flush
)
if anyone is a SO user and would like the SO reputation points for
answering it there, feel free as I'll be keeping track of this issue
everywhere I post it. :)
Hope someone out there can help me! :)
I started switching some pre-existing nHibernate code in a Sharepoint-
based ASP.NET project from eager loading and a new session every
database hit, to lazy loading and a session for the duration of the
HTTP request, and started running into a problem.
When we create an Item in this system, there are some many-to-one
relationships that are populated by dropdowns. That gets us the ID,
which is enough to save to the database.
In order to perform some post-save tasks like email notification, we
then load that same item back, which previously would get us the
entire object tree populated.
However, since the change to lazy loading and a session with the
lifetime of the entire request, we've been getting
NullReferenceExceptions from properties below Item that are
mysteriously null.
We load the item through nHibernate into changedItem. The call that's
failing is:
changedItem.PaperMedia.FormsAnalyst.User.Contact.Name
PaperMedia is fully populated, but everything on FormsAnalyst is null
except the ID.
This is the same state as when we saved it, so one possible cause of
this problem is the Item being cached and simply retrieved, nHibernate
thus being ignorant of the actual values from the database. However,
I'm committing the transaction, plus explicitly calling Flush() on the
session, between the save and the subsequent load, so if that's the
case, neither Commit() nor Flush() is not having any effect on the
cache.
I have changed these properties in the relevant hbm.xml files to be
lazy="false", and have SetFetchMode FetchMode.Eager for all of them
during the query as well, to no effect. I also tried fetch="join" on
them.
I was also considering max_fetch_depth as the issue. If I call Refresh
(changedItem) on the session, it has no effect. However, if I call
Refresh(changedItem.PaperMedia), it will populate all the way down to
Name. This would seem to discount max_fetch_depth as the problem, but
I've nonetheless made an attempt to increase it, setting it to 6 in
the hibernate.cfg.xml as well as SetProperty("max_fetch_depth", "6")
on the configuration instance while creating the session factory, and
these have had no effect either.
I don't know what else to try.
Anyone seen anything like that before? I'm new to nHibernate so it
might be something simple...
--
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.