OK, I built a workaround, though this is very ugly, but at least it
works as long as there is no other solution:
I built a helper class mapping to the same table which looks like
this:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="BookToolV2" namespace="BookTool">
<class name="ChapterHelper" table="CHAPTER" lazy="true" >
<id name="ChapterId" column="ID_CHAPTER" type="Decimal">
<generator class="assigned" />
</id>
<property name="BookId" type="Decimal" column="ID_BOOK" />
<property name="ChapterType" type="Decimal" not-null="true" column="CHAPTER_TYPE"/>
</class>
</hibernate-mapping>
Code:
class ChapterHelper
{
public virtual Decimal ChapterHelperId { get; set; }
public virtual Decimal BookId { get; set; }
public virtual Decimal ChapterType { get; set; }
}
I use this in the onFlushDirty Event of the Interceptor on the main
Session:
Code:
class MyInterceptor: IInterceptor
{
...
public bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
{
if (entity.GetType().IsSubclassOf(typeof(Chapter)))
{
Chapter chapter = (Chapter)entity;
Chapter checkChapter;
ISession checkSession = NHibernateFactory.CheckSession; // a second session
checkChapter = (Chapter)checkSession.Get(typeof(Chapter), (Object)chapter.Id);
if (checkChapter == null)
{
DialogResult result = MessageBox.Show("Instance was not found in DB!");
ChapterHelper helpchapter= new ChapterHelper();
helpchapter.ChapterHelperId =chapter.Id;
helpchapter.BookId = chapter.BookId;
helpchapter.ChapterType = chapter.GetStypeTypeId(); // in the main mapping file this is a discriminator
checkSession.Save(helpchapter);
checkSession.Flush();
}
}
return false;
}
...
}
I hope to find a better solution, because this is really really ugly = (
Any advice would be great!!!
Thank you! [/code]