Hi,
I have a problem with a superclass - joined-subclass model. The
superclass fields are not persisted (no query to the database) when
I'm updating the object (and the superclass fields have been modified
of course).
Here is the model:
public class BaseAudit
{
[Property]
public string Modifier { get; private set; }
[Property]
public DateTime Modified { get; private set; }
[Property]
public long Version { get; private set; }
[Property]
public int SchemaVersion { get; private set; }
[Property]
public string Type { get; private set; }
}
[ActiveRecord("DBDocument"), JoinedBase]
public class DocumentAR : BaseAudit --> superclass
{
[PrimaryKey("_id")]
public long Id { get; private set; }
}
[ActiveRecord("DBSubDocument")]
public class SubDocumentAR : BaseAudit ---> joined-subclass
{
[JoinedKey("_id")]
public long DocumentId { get; private set; }
}
Now the nhibernate mapping (generated by ActiveRecord):
<?xml version="1.0" encoding="utf-16"?>
<hibernate-mapping auto-import="true" default-lazy="false"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-
mapping-2.2">
<class name="App.ARModel.DocumentAR, Rhino.Sst.App"
table="DBDocument" polymorphism="explicit">
<id name="Id" access="property" column="_id" type="Int64" unsaved-
value="0">
<generator class="hilo">
<param name="table">Nolics_LastID</param>
<param name="column">LastID</param>
<param name="max_lo">16</param>
</generator>
</id>
<property name="Modifier" access="property" type="String">
<column name="Modifier"/>
</property>
<property name="Modified" access="property"
type="System.DateTime">
<column name="Modified"/>
</property>
<property name="Version" access="property" type="Int64">
<column name="Version"/>
</property>
<property name="SchemaVersion" access="property" type="Int32">
<column name="SchemaVersion"/>
</property>
<property name="Type" access="property" type="String">
<column name="Type"/>
</property>
<joined-subclass name="App.ARModel.SubDocumentAR, Rhino.Sst.App"
table="DBSubDocument">
<key column="_id" />
<property name="DossierId" access="property" type="Int64">
<column name="DossierId"/>
</property>
</joined-subclass>
</class>
</hibernate-mapping>
And now the faulty example:
SubDocumentAR doc;
using(new TransactionScope())
{
doc = new SubDocumentAR();
ActiveRecordMediator.Save(doc);
}
using(new TransactionScope())
{
var doc2 = ActiveRecordMediator.Find(doc.Id);
doc2.DossierId = 1;
ActiveRecordMediator.Save(doc2);
Assert.That( doc2.Modified, Is.Not.EqualTo(doc.Modified) ); -->
This fails because, both the entity and the super-class are not
updated (see below for how we update the audit information).
}
----
We use an audit system using three event listeners, OnPreInsert,
OnPreUpdate and OnPostDelete. Simply updating the appropriate field in
the entity and in the state.
Here is the code for the OnPreUpdate method of the event listener :
public bool OnPreUpdate(PreUpdateEvent preUpdateEvent)
{
var entity = preUpdateEvent.Entity as BaseAudit;
if (entity != null)
{
UpdateAuditInformation(entity, preUpdateEvent.State,
preUpdateEvent.Persister, preUpdateEvent.Source); --> updating both
the entity and the State
}
return false; --> when I break into debug here, both the
entity and the state have been modified.
}
----
The model and the audit system cannot be modified, since we are trying
to replicate an old ORMapper functionnality.
We are using NHibernate 2.1.0.1001 with Castle.ActiveRecord
1.0.3.5363.
Any help would be greatly appreciated.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.