Hello there I hope someone can help me with my mapping problem. I have two entities that both have relationships to eachother. The entities looks as so:
Code:
public class Asset : EntityBase
{
private long _id;
private AssetVersion _currentVersion;
private IList<AssetVersion> _allVersions;
}
public class AssetVersion
{
private long _id;
private Asset _asset;
private int _versionNumber;
}
The mapping files look as so:
Code:
<class name="...Asset" table="Asset">
<id name="Id" column="Id" type="Int64" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="CurrentVersion" class="...AssetVersion" column="CurrentVersion"/>
<bag name="AllVersions" inverse="true" order-by="Version ASC">
<key column="AssetId"/>
<one-to-many class="...Asset"/>
</bag>
</class>
<class name="...AssetVersion" table="AssetVersion">
<id name="Id" column="Id" type="Int64" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="Asset" class="...Asset" column="AssetId"/>
<property name="VersionNumber" column="VersionNumber" type="Int32" not-null="true"/>
</class>
As you can see, the Asset class has a reference to a single AssetVersion entity, and also to a collection of AssetVersion entities. However when I try to assign a (persisted) AssetVersion to the Asset.CurrentVersion field, NHibernate falls over with this message:
Code:
Unable to evaluate the expression. Operation not supported. Unknown error: 0x8004f0ef.
It is not an exception that i can see - when this happens the program closes and i am even chucked out of the debugger!
I have read in the book (Beginning Hibernate: From Novice To Professional - Apress), that it is poor design to use bidirectional mapping. In this case, is there a better way to achieve what i am looking for? I appreciate any help anyone can give me!