Hi,

I've build an entity manager which takes care of basic retrieval
actions. One of the methods retrieves all entities of certain
type(method implementation see below).
formerly it was parameterless Method and it worked well. Now I want to
give the developer the possibility to use that method with a parameter
which forces the retrieval of entities from the database instead of
looking at the firstLevelCache.
If the boolean is set to true the session is cleared and therefore no
entites remain in the firstLevelCache. NH has to load them all
directly from the database The method does that , but now I have
problems that lazy loaded one many relations are not available
anymore.
If I use  CreateQuery(pHQLstring) instead of CreateCriteria(typeof(T))
it works can somebody explain me the problem?

What can I do to change that Method (with CreateCriteria(typeof(T)))in
a way that I can force NH to load entities without using the
firstLevel cache and still have lazy loaded entities available.


Thanks antoschka

private static IList<T> getItems<T>(bool pRetrieveFromDatabase) where
T : new()
        {
            IList<T> items = null;
            ISession session =
SessionProviderStatic.Instance.GetSession();
            if (pRetrieveFromDatabase) session.Clear();
            ITransaction trans = null;

            try
            {
                trans = session.BeginTransaction();
                ICriteria query = session.CreateCriteria(typeof(T));
                items = query.List<T>();

                trans.Commit();
                //foreach (object currentEntry in items)
((T)currentEntry).PersistenceInfo = PersistenceStatus.persistent;
                return items;
            }

            catch (Exception ex)
            {
                trans.Rollback();
                throw new DataAccessException("Error getting items",
ex);
            }
            finally
            {
                SessionProviderStatic.Instance.CloseSession();
            }

        }
--~--~---------~--~----~------------~-------~--~----~
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