I’ve seen many posts Re: the above problem (Unable to locate persister). However the problem we are having is that this error occurs randomly in our web application (ASP.Net MVC). Also when we restart the app pool the problem goes away.
Mostly the error happens for an entity that is cached. See mappings below.
<class name="Privilege" table="PRIVILEGE" lazy="false">
<cache usage="nonstrict-read-write"/>
<id name="Id" />
<property name="Description" column="DESCRIPTION" not-null="true" />
<set name="RoleCollection" table="PRIVILEGE_ROLE">
<cache usage="nonstrict-read-write"/>
<key column="PRIVILEGE_ID" foreign-key="PRIVILEGE_ROLE_FK1" />
<many-to-many class="Role" column="ROLE_ID" foreign-key="PRIVILEGE_ROLE_FK2" />
</set>
<class name="Role" table="ROLE" lazy="false" >
<cache usage="nonstrict-read-write"/>
<id name="Id" />
<property name="Description" column="DESCRIPTION" not-null="true" />
<set name="PrincipalCollection" table="ROLE_PRINCIPAL">
<cache usage="nonstrict-read-write"/>
<key column="ROLE_ID" foreign-key="ROLE_PRINCIPAL_FK1" />
<many-to-many class="Principal" column="PRINCIPAL_ID" foreign-key="ROLE_PRINCIPAL_FK2" />
</set>
Could this be related to a NHb Session corruption? We’d highly appreciate if someone could at least point us in a direction of troubleshooting this as it’s not possible to consistently reproduce the problem either. (We use NHb 3.1.0.4000)
Sorry for being late to provide an update.
I’ve figured out the reason for this and it happens to be the way the Nhibernate Session Factory was being initialized.
Solution
Not only is this approach fixed the issue, I think it’s a better option from a performance point of view. Eagerly doing the costly operation of Session Factory initialization rather than putting more weight on a particular user request is more reflective of the problem at hand.
We are running this modified version in prod for a month now without any issues.