Is there a way to tell NHibernate not to return the object from the first level cache for certain objects?
The problem is that I have several objects, because of FKPK one-to-one relationships and joined subclasses that share the same Guid key. If i retreive an object with a key, NHibernate always returns the same object from the first level cache even when I query for another object with the same key, and I get errors when it tries to cast them.
Below is the exception form the log:
Code:
Exception: NHibernate.WrongClassException
Message: Object with id: 612a3bd7-45ee-4f9f-8621-065f14bb9368 was not of the specified sublcass: Owner (loading object was of wrong class)
Source: NHibernate
at NHibernate.Loader.Loader.InstanceAlreadyLoaded(IDataReader rs, Int32 i, ILoadable persister, String suffix, Key key, Object obj, LockMode lockMode, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, String[] suffixes, Key[] keys, Object optionalObject, Key optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, IList hydratedObjects, Object optionalObject, Object optionalId, Key[] keys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
at NHibernate.Loader.CriteriaLoader.List(ISessionImplementor session)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)