I know somewhere I've overlooked something simple, but my eyes grow weary and I thought I would throw this out to the general populous, to mock me as to the simplicity of this problem.
So mocking aside:
Content is a generic content class, containing some simple objects to handle chunks of web related content (blog post, image in Flickr, etc). There are different contents for different types of sources. In this case, FlickrContent relates to content from Flickr (surprisingly) and inherits from Content.
Source contains a IList of Content. There are different sources for different types of data. So FlickrSource relates to a source from Flickr which still contains a List of Content.
The bit causing all the trouble is this:
Code:
Content searchContent = new FlickrContent(photoDoc);
searchContent.Source = this;
if (!Content.Contains(searchContent))
Content.Add(searchContent);
Content is of type Content. Apologies for the slightly ambiguous property naming, it's a headdesk moment that will be rectified on the first code clean-up.
The mapping file for content looks like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="PlanetoidAPI.Objects" assembly="PlanetoidAPI">
<class name="PlanetoidAPI.Objects.Content" table="PL_CONTENT">
<id name="Id">
<column name="PL_CN_ID" sql-type="int" not-null="true" />
<generator class="identity" />
</id>
<property ... />
<many-to-one name="Source" class="PlanetoidAPI.Objects.Source" column="PL_CN_SC_ID" not-null="true" />
</class>
</hibernate-mapping>
and the mapping file for source looks like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="PlanetoidAPI.Objects" assembly="PlanetoidAPI">
<class name="PlanetoidAPI.Objects.Source" table="PL_SOURCE">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by NHibernate with the UUID pattern. -->
<id name="Id">
<column name="PL_SC_ID" sql-type="int" not-null="true" />
<generator class="identity" />
</id>
<discriminator column="PL_SC_TYPE" type="string" />
...
<bag name="Content" inverse="true" cascade="all">
<key column="PL_CN_SC_ID"/>
<one-to-many class="PlanetoidAPI.Objects.Content"/>
</bag>
<subclass name="RssSource" discriminator-value="Rss" />
<subclass name="FlickrSource" discriminator-value="Flickr" />
</class>
</hibernate-mapping>
So what we've got here folks is a pretty straightforward parent child bi-directional relationship. Everything is fine and dandy if you want to add objects of type Content to the Content collection, but if I attempt to add an object of type FlickrContent to the Content collection (that really is a terrible name) and then update that back to the database, we get:
Unknown entity class: PlanetoidAPI.Objects.FlickrContent
which in one sense is fair do, FlickrContent is not explicitly specified, but shouldn't it fall back to the mapping for type Content instead? If I am completely misreading this, is there a way to force this behaviour? I'm trying to avoid having to add every derivative of Content as some kind of subclass.
Many Thanks,
Kian Ryan