Hi,
I have a Category class with a couple of collections of Properties associated with it; Read Only and Default. I've saved all these properties in one table and differentiated between them using a discriminator.
I think I should be able to define a couple of bags on Category and just specify which class they should come from and NHibernate would give me back my collections based on the discriminator.
However I have had to define where clauses on my bags. So yes it works; I'm not hugely worried about it, but it'd be really good to know if I've done my mapping incorrectly.
Thanks in advance,
Brett.
Hibernate version: 1.2 Beta
Mapping documents:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
<class name="Domain.DefaultProperty, Core"
table="nrp_CategoryDefault" discriminator-value="0" >
<id name="ID" type="Int32" column="CategoryDefaultID" unsaved-value="0">
<generator class="identity" />
</id>
<discriminator column="ReadOnly" type="Char" />
<many-to-one name="ForCategory" column="CategoryID" class="Domain.Category, Core" />
<many-to-one name="OfType" column="PropertyID" class="Domain.Property, Core" />
<property name="Value" column="PropertyValue" />
<subclass name="Domain.ReadOnlyDefaultProperty, Core" discriminator-value="1">
</subclass>
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
<class name="Domain.Category, Core" table="nrp_Category">
<id name="ID" type="Int32" column="CategoryID" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Name" column="CategoryName" type="string" />
<bag name="DefaultProperties" inverse="true" lazy="true" where="ReadOnly='0'">
<key column="CategoryID" />
<one-to-many class="Domain.DefaultProperty, Core" />
</bag>
<bag name="ReadOnlyProperties" inverse="true" lazy="true" where="ReadOnly='1'">
<key column="CategoryID" />
<one-to-many class="Domain.ReadOnlyDefaultProperty, Core" />
</bag>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs: None
No exceptions.
Name and version of the database you are using: SQL Server 2000
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: