I had a problem with a Plenty to many relationship and a session in nHibernate in my web application.
The object I'm working with always supported its connection to the session, although it was sent to and from the server. Never had a problem. Still. I added a new, many-to-many relationship with my class.
This shows that the Many-To-Many mapping (names changed to make more sense):
<bag name="ProductsToCategory" table="Tab_ProductsToCategory"" cascade="all-delete-orphan">
<key column="ProductID" />
<many-to-many class="CategoryClass" column="CategoryID" />
</bag>
When I run the code, it works with bootstrapping. However, subsequent calls to the server that accesses this object - the object is supported in a web session - therefore, this collection needs to be broken and thrown this error:
failed to lazily initialize collection, session or session closed
It’s strange. I wondered if there is anything in this regard as a many-to-many association that is causing the problem? This many-to-many is added only to this class, and not to the class at the other end of the mapping, "CategoryClass", because I do not need it. The object seems good until I add this mapping.
Any ideas?
ALSO: I tried just checking to see if there is an object in the session. This is not true. So I call:, session.refresh(productClass)and everything is updated correctly, including my unpleasant mapping. However. It loads every item in the TWICE collection! the collection has twice as many elements as in the database, and each element is displayed twice. If I could get an answer to this problem, that previous question doesn't matter.
, , . .