I have a many to many relationship between A and B. (I know I can consider refactoring etc, but that's another matter). my Code does something like this:
// given aId is the Id of an instance of A, and A has a many to many set of B's
A a = myActiveSession.Get<A>(aId);
a.Bs.Add(new B() {Name="dave"});
and I get an exception because a.Bs is NULL. this only happens in the context of a test suite, and when I run the single test I get a set and everything is ok. I expect that since the default is lazy fetch, Bs will be initialized when I access the property getter, but if this fails I expect to get an exception, and not simply null... since this way I have no immediate clue what caused this. any ideas?
PS: this is the mapping:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="MyNamespace" assembly="MyAssembly">
<class name="A" table="A" dynamic-update="true">
<id name="id" type="integer" access="field">
<column name="ID"/>
<generator class="native"/>
</id>
<property name="name" type="string" access="field"/>
<set name="Bs" table="A_B">
<key column="a_id"/>
<many-to-many column="b_id" class="B" />
</set>
</class>
</hibernate-mapping>
UPDATE: I've managed to get this to work when I fixed some code that did session cleanup (see @Darin Dimitrov's suggestion), however, I still don't understand what could have caused this strange behavior (instead of receiving some clear exception). so at the moment this remains a mystery.