Hi!
Here are my relevant classes:
public class ArticleMetadata
{
public long ID { get; set; }
public string Slug { get; set; }
}
public class Article : ArticleMetadata
{
// This is a massive CLOB, hence separate class
public string Content { get; set; }
}
public class Section
{
public long ID { get; set; }
public IList<ArticleMetadata> Articles { get; set; }
}
And here are relevant mapping parts:
<class name="Article" table="Article">
</class>
<!-- Note that there's no explicit NHibernate inheritance mapping here -->
<class name="ArticleMetadata" table="Article">
</class>
<class name="Section" table="Section">
<bag name="Articles" cascade="all-delete-orphan" inverse="true" lazy="false">
<key column="SectionID" />
<one-to-many class="ArticleMetadata" />
</bag>
</class>
Hope it's all clear up until now.
What I'm trying to do is as follows: when selecting my Section
objects, I want them to contain only "lightweight" ArticleMetadata
objects. But when saving Section
to the DB, I want NHibernate to persist Article
objects as well:
var section = new Section();
section.Articles.Add(new ArticleMetadata("a1"));
section.Articles.Add(new Article("a2", "massive clob"));
session.SaveOrUpdate(section);
Currently, SaveOrUpdate
exit without any errors whatsoever, but a full-blown Article
object gets saved only partially. That is, value of its' Content
property never makes it to the DB.
Saving Article
separately (session.Save(new Article(...));
) works as expected, saving all mapped properties.
To sum it up: I want to add both ArticleMetadata
and Article
objects to Section.Articles
collection, and want them to be saved appropriately. Is this kind of behavior possible at all?