Greetings,
I have ran into an odd issue when trying to load an entity. The call to load (or get) fails the first time, but if I try again in the same session everything works OK. I noticed in the logs that it is giving me a fail for entity id 1000, but the key I am passing in is 1001.
I debugged the NHibernate code, and it appears to be not working correctly somewhere in the Loader.cs file, in the call to:
private IList DoQuery(
ISessionImplementor session,
QueryParameters queryParameters,
bool returnProxies)
{...}
Does anyone have any ideas about what I could be doing wrong?
Thanks in advance,
J.
Hibernate version: 1.2.0
Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="Marshall.GeoResultsLibrary.Hansen.Entities.ACTDEFNEntity, Marshall.GeoResultsLibrary.Hansen.Entities" table="[ACTDEFN]" >
<id name="Id" column="ACTKEY" type="System.Int32" unsaved-value="null">
<generator class="assigned"/>
</id>
<property name="ACTCODE" column="ACTCODE" access="field.pascalcase-underscore" not-null="true" type="System.String" length="6" insert="true" update="true"/>
<property name="ACTDESC" column="ACTDESC" access="field.pascalcase-underscore" not-null="false" type="System.String" length="30" insert="true" update="true"/>
<property name="ACTGRP" column="ACTGRP" access="field.pascalcase-underscore" not-null="false" type="System.String" length="6" insert="true" update="true"/>
<property name="ACTTYPE" column="ACTTYPE" access="field.pascalcase-underscore" not-null="false" type="System.String" length="6" insert="true" update="true"/>
<property name="ADDBY" column="ADDBY" access="field.pascalcase-underscore" not-null="false" type="System.String" length="30" insert="true" update="true"/>
<property name="ADDDTTM" column="ADDDTTM" access="field.pascalcase-underscore" not-null="false" type="System.DateTime" insert="true" update="true"/>
<property name="ADP" column="ADP" access="field.pascalcase-underscore" not-null="false" type="System.Double" insert="true" update="true"/>
<property name="ADPUOM" column="ADPUOM" access="field.pascalcase-underscore" not-null="false" type="System.String" length="4" insert="true" update="true"/>
<property name="ASSVALTYPE" column="ASSVALTYPE" access="field.pascalcase-underscore" not-null="false" type="System.String" length="15" insert="true" update="true"/>
<property name="COMMENTS" column="COMMENTS" access="field.pascalcase-underscore" not-null="false" type="System.String" insert="true" update="true"/>
<property name="COMPFLAG" column="COMPFLAG" access="field.pascalcase-underscore" not-null="false" type="System.String" length="1" insert="true" update="true"/>
<property name="EXPDATE" column="EXPDATE" access="field.pascalcase-underscore" not-null="false" type="System.DateTime" insert="true" update="true"/>
<property name="FHYFTKEY" column="FHYFTKEY" access="field.pascalcase-underscore" not-null="false" type="System.Int32" insert="true" update="true"/>
<property name="FRMLAKEY" column="FRMLAKEY" access="field.pascalcase-underscore" not-null="false" type="System.Int32" insert="true" update="true"/>
<property name="MODBY" column="MODBY" access="field.pascalcase-underscore" not-null="false" type="System.String" length="30" insert="true" update="true"/>
<property name="MODDTTM" column="MODDTTM" access="field.pascalcase-underscore" not-null="false" type="System.DateTime" insert="true" update="true"/>
<property name="OUTOFSERV" column="OUTOFSERV" access="field.pascalcase-underscore" not-null="false" type="System.String" length="1" insert="true" update="true"/>
<property name="POOLKEY" column="POOLKEY" access="field.pascalcase-underscore" not-null="false" type="System.Int32" insert="true" update="true"/>
<property name="POTSERVREQ" column="POTSERVREQ" access="field.pascalcase-underscore" not-null="false" type="System.String" length="1" insert="true" update="true"/>
<property name="SUSPDAYS" column="SUSPDAYS" access="field.pascalcase-underscore" not-null="false" type="System.Int32" insert="true" update="true"/>
<property name="SUSPHRS" column="SUSPHRS" access="field.pascalcase-underscore" not-null="false" type="System.Int32" insert="true" update="true"/>
<property name="SYSFLAG" column="SYSFLAG" access="field.pascalcase-underscore" not-null="false" type="System.Int32" insert="true" update="true"/>
<property name="WFACTOR" column="WFACTOR" access="field.pascalcase-underscore" not-null="false" type="System.Int16" insert="true" update="true"/>
<!--<set name="FKCOMPSAFEHISTORY" cascade="none" inverse="true" lazy="true" access="field.pascalcase-underscore">
<key>
<column name="ACTKEY"/>
</key>
<one-to-many class="Marshall.GeoResultsLibrary.Hansen.Entities.COMPSAFEEntity, Portland_hansen.Server"/>
</set>-->
<set name="FKACTTASKACTDEFN" cascade="none" inverse="true" lazy="false" access="field.pascalcase-underscore">
<key>
<column name="ACTKEY"/>
</key>
<one-to-many class="Marshall.GeoResultsLibrary.Hansen.Entities.ACTTASKEntity, Marshall.GeoResultsLibrary.Hansen.Entities"/>
</set>
<set name="FKHISTORYACTDEFN" cascade="none" inverse="true" lazy="true" access="field.pascalcase-underscore">
<key>
<column name="ACTKEY"/>
</key>
<one-to-many class="Marshall.GeoResultsLibrary.Hansen.Entities.HISTORYEntity, Marshall.GeoResultsLibrary.Hansen.Entities"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Code:
public static E Load<E>(int key, ISession session)
{
if (null == session)
{
_logger.Log("Could not create database connection.", LogLevel.Error);
throw new Exception(string.Intern("Could not create database connection."));
}
try
{
return (E)session.Get<E>(key); // also tried session.Load
}
catch (Exception e)
{
_logger.Log(string.Format("Error when trying to load Entity {0}. Message: {1}.",
typeof(E).Name, e.Message)
, LogLevel.Error);
throw;
}
}
Full stack trace of any exception that occurs:
02 Dec 2008 16:35:23 [6320] ERROR Marshall.GeoResultsServer.HansenBusiness.Services.WorkOrderIOService (null) - No row with the given identifier exists: 1000, of class: Marshall.GeoResultsLibrary.Hansen.Entities.TASKDEFNEntity
NHibernate.UnresolvableObjectException: No row with the given identifier exists: 1000, of class: Marshall.GeoResultsLibrary.Hansen.Entities.TASKDEFNEntity
at NHibernate.UnresolvableObjectException.ThrowIfNull(Object o, Object id, Type clazz) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\UnresolvableObjectException.cs:line 59
at NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id, Boolean eager, Boolean isNullable) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 2483
at NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Type\EntityType.cs:line 262
at NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session, Object owner) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Type\EntityType.cs:line 282
at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 2954
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Loader\Loader.cs:line 615
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Loader\Loader.cs:line 475
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Loader\Loader.cs:line 181
at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Loader\Loader.cs:line 1621
at NHibernate.Loader.Collection.CollectionLoader.Initialize(Object id, ISessionImplementor session) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Loader\Collection\CollectionLoader.cs:line 31
at NHibernate.Persister.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Persister\Collection\AbstractCollectionPersister.cs:line 419
at NHibernate.Impl.SessionImpl.InitializeCollection(IPersistentCollection collection, Boolean writing) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 4494
at NHibernate.Collection.AbstractPersistentCollection.ForceInitialization() in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Collection\AbstractPersistentCollection.cs:line 450
at NHibernate.Impl.SessionImpl.InitializeNonLazyCollections() in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 4302
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Loader\Loader.cs:line 187
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Type optionalEntityName, Object optionalIdentifier, IEntityPersister persister) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Loader\Loader.cs:line 1521
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Loader\Entity\AbstractEntityLoader.cs:line 41
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id, Object optionalObject, ISessionImplementor session) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Loader\Entity\AbstractEntityLoader.cs:line 36
at NHibernate.Persister.Entity.AbstractEntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2477
at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 2808
at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 2544
at NHibernate.Impl.SessionImpl.Load(Type clazz, Object id) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 2406
at NHibernate.Impl.SessionImpl.Load[T](Object id) in c:\Users\jlong\Downloads\NHibernate-1.2.0.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 2420
at Marshall.GeoResultsServer.HansenBusiness.Services.WorkOrderIOService.GetWorkOrder(Int32 id) in C:\SRC\7000-GeoResultsMobile\GeoResultsServer\Source\Modules\HansenBusiness\HansenBusiness\Services\WorkOrderIOService.cs:line 157
Name and version of the database you are using:
sqlserver 2005
Sql:
SELECT actdefnent0_.ACTKEY as ACTKEY19_0_, actdefnent0_.ACTCODE as ACTCODE19_0_, actdefnent0_.ACTDESC as ACTDESC19_0_, actdefnent0_.ACTGRP as ACTGRP19_0_, actdefnent0_.ACTTYPE as ACTTYPE19_0_, actdefnent0_.ADDBY as ADDBY19_0_, actdefnent0_.ADDDTTM as ADDDTTM19_0_, actdefnent0_.ADP as ADP19_0_, actdefnent0_.ADPUOM as ADPUOM19_0_, actdefnent0_.ASSVALTYPE as ASSVALTYPE19_0_, actdefnent0_.COMMENTS as COMMENTS19_0_, actdefnent0_.COMPFLAG as COMPFLAG19_0_, actdefnent0_.EXPDATE as EXPDATE19_0_, actdefnent0_.FHYFTKEY as FHYFTKEY19_0_, actdefnent0_.FRMLAKEY as FRMLAKEY19_0_, actdefnent0_.MODBY as MODBY19_0_, actdefnent0_.MODDTTM as MODDTTM19_0_, actdefnent0_.OUTOFSERV as OUTOFSERV19_0_, actdefnent0_.POOLKEY as POOLKEY19_0_, actdefnent0_.POTSERVREQ as POTSERVREQ19_0_, actdefnent0_.SUSPDAYS as SUSPDAYS19_0_, actdefnent0_.SUSPHRS as SUSPHRS19_0_, actdefnent0_.SYSFLAG as SYSFLAG19_0_, actdefnent0_.WFACTOR as WFACTOR19_0_ FROM IMSV7.[ACTDEFN] actdefnent0_ WHERE actdefnent0_.ACTKEY=@p0