Hi guys,
I have a problem I've encountered today. It is about loading object via session.Load(). As you all know that session.Load() creates a proxy object if it can and it does so in my case. Then if you call a property or a method it will first load the entity and then executes the property/method.
There are some cases when calling to property of the proxied-entity generates an IndexOutOfRangeException. The exception message states that it couldn't find the column in the query results. It happens rarely in an unpredictable way.
Well, the problem is that I have such a column in sql excerpt. Here is the stack trace:
Code:
at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
at NHibernate.Driver.NHybridDataReader.GetOrdinal(String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
at NHibernate.Loader.Loader.GetKeyFromResultSet(Int32 i, ILoadable persister, Object id, IDataReader rs, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Type optionalEntityName, Object optionalIdentifier, IEntityPersister persister)
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id, Object optionalObject, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted)
at NHibernate.Impl.SessionImpl.ImmediateLoad(Type clazz, Object id)
at NHibernate.Proxy.LazyInitializer.Initialize()
at NHibernate.Proxy.CastleLazyInitializer.Intercept(IInvocation invocation, Object[] args)
NHibernate version I use is 1.2.1.4000 and it is used on MS SQL 2005.
I've checked the forum, but there seems nothing like my problem. Has anyone encountered this before? Maybe I should rewrite the code so it will use session.Get instead of session.Load?