Hi there,
everthing is now working really fine for me :-) I got just one more case (i hope) to discuss.
I got an polymorphic bidirectional 1:m association between Kategorie and Produkt where Produkt is an abstract base class for Books, Videos and Cd, Cd is although abstract baseclass for MusikCd and CdRom . I implemented it as an 1:m parent/child association using an Set. That works really fine for inserting, deleting etc. as long as the Kategorie object is already in the database... If i create a new one and then a new produkt and bind them together i got an exception like : Object reference not set to an instance of an object when doing kat.Produkt.Add(produkt); if i load kat of the database its working fine...
here some code snippet:
Code:
Produkt vid = new Video(...);
Kategorie kat = new Kategorie(...);
vid.Kategorie = kat;
kat.Produkte.Add(vid); // <-- Exception here...
session.Save(kat);
transaction.Commit();
I although tried to flush() the new Kategorie (so it got an Id) same for Produkt... is not working... If i use session.Load oder Get as is said, its fine...
I think it cant be a big thing, but i dont get it.
here is the mapping:
Code:
<set name="Produkte" cascade="all-delete-orphan" inverse="true" >
<key column="KategorieId"/>
<one-to-many class="NHTest.Produkt, NHTest"/>
</set>
For Kategorie
And for Produkt:
Code:
<many-to-one name="Kategorie" column="KategorieId" class="NHTest.Kategorie, NHTest"/>
All Id-Generators are high-low and i did set unsave-value="0". Just in case
Thx in advance!
Regards
Chris