Hi,
I might just be doing something dumb but since it only happens in a specific case i'm wondering if it is a bug:
I have a table called "Media" which has a mapping with "Selections"
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="MyApp.Data.BusinessObjects" assembly="MyApp.Data">
<class name="MyApp.Data.BusinessObjects.Media, MyApp.Data" table="media" where="deleted = 0" lazy="true">
<id name="Id" column="id">
<generator class="assigned" />
</id>
<property name="Title" column="title" />
<property name="Sabam" column="sabam" />
<property name="Disc" column="disc" />
<property name="Track" column="track" />
<property name="Year" column="year" />
<property name="Duration" column="duration" />
<property name="Leadin" column="leadin" />
<property name="Leadout" column="leadout" />
<property name="Validfrom" column="validfrom" />
<property name="Validuntil" column="validuntil" />
<property name="Class" column="class" />
<property name="Published" column="published" />
<property name="Reccreated" column="reccreated" />
<property name="Reccreater" column="reccreater" />
<property name="Recmodified" column="recmodified" />
<property name="Recmodifier" column="recmodifier" />
<property name="Recdeleted" column="recdeleted" />
<property name="Recdeleter" column="recdeleter" />
<property name="Deleted" column="deleted" />
<many-to-one name="MediaMember" column="childid" class="Media"/>
<many-to-one name="File1" column="filedefault" class="File"/>
<many-to-one name="File2" column="filesource" class="File"/>
<many-to-one name="FileType" column="filetype" class="FileType"/>
<many-to-one name="MediaGenre" column="genre" class="MediaGenre"/>
<many-to-one name="Language" column="language" class="Language"/>
<many-to-one name="Library" column="library" class="Library"/>
<many-to-one name="MediaStatus" column="status" class="MediaStatus"/>
<many-to-one name="MediaType" column="mediatype" class="MediaType"/>
<many-to-one name="MediaVoice" column="voice" class="MediaVoice"/>
<many-to-one name="Author" column="author" class="Author"/>
<many-to-one name="Country" column="country" class="Country"/>
<many-to-one name="MediaGender" column="gender" class="MediaGender"/>
<many-to-one name="MediaId3genre" column="id3genre" class="MediaId3genre"/>
<many-to-one name="MediaTempo" column="tempo" class="MediaTempo"/>
<bag name="CollectionlistMediamembers" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
<key column="media"></key>
<one-to-many class="CollectionlistMediamember"></one-to-many>
</bag>
<bag name="Files" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
<key column="media_id"></key>
<one-to-many class="File"></one-to-many>
</bag>
<bag name="MediaCustomers" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
<key column="media"></key>
<one-to-many class="MediaCustomer"></one-to-many>
</bag>
<bag name="PlaylistMedia" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
<key column="media"></key>
<one-to-many class="PlaylistMedium"></one-to-many>
</bag>
<bag name="SelectionlistMediamembers" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
<key column="media"></key>
<one-to-many class="SelectionlistMediamember"></one-to-many>
</bag>
<sql-delete>update media set deleted = 1,recdeleted = now() where id = ?</sql-delete>
</class>
</hibernate-mapping>
Now , when i create a new media, add selectionlistmediamembers to them, this is NOT saved in persitence:
Code:
Media oMedia = new Media();
oMedia.Id = Guid.NewGuid().tostring();
//fill out all other parameters here
Selectionlistmediamember oSelMem = new Selectionlistmediamember();
oSelMem.Id = Guid.newGuid().tostring();
//fill out other stuff
oMedia.SelectionlistMediaMembers.add(oSelMem);
oMediaManager.Save(oMedia);
/* At this point, i get an error saying:
nhibernate.stalestateexception unexpected row count 0 expected 1
*/
when NOT adding the selectionmediamembers, saving the media and THEN adding the members and updating, it does work. The other effort was trying to save the selectionmediamembers first but this cannot be done since the foreign key does not allow me to save items who's parent cannot be found (logically)
Am i doing something wrong here or is there an issue with the caching of the object / my mapping ?
Many thanks in advance !