In my ASP.NET webforms app, I am getting the above exception predominately, along with:
– A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance: Persistence.Product.ModelMap
– collection was processed twice by flush()
– Found shared references to a collection: Persistence.Product.ModelMap
when I am retrieving products. It happens only when I have two or more requests hit the server at once. I am using one session per request.
The property, ModelMap, is defined as follows in the Hibernate XML in the Products mapping definition:
<bag name="ModelMap" table="MapProductModel" cascade="all-delete-orphan" lazy="true" inverse="true" where="IsDeleted=0">
<key column="fkProductId" />
<one-to-many class="MapProductModel" />
</bag>
This happens on the following line of code
IList<T> itemList = criteria.List<T>();
When the retrieving the product.
Any help greatly appreciated, Google didn’t really turn up anything.
ASP.NET is multithreaded, so requests will come in on multiple threads in the same HTTP request. You should be using NHibernate’s web session context (or other means); creating a new session per HTTP request is not enough. See http://nhibernate.info/doc/nhibernate-reference/architecture.html#architecture-current-session