|
From: Filip K. (JIRA) <nh...@gm...> - 2011-03-28 07:19:18
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Filip Kinsky updated NH-2596:
-----------------------------
Attachment: NHListenerTest_NH31.zip
test solution with NHibernate 3.1 GA
> changes made in IPreInsert/UpdateEventListener are not persisted into DB on inherited classes
> ---------------------------------------------------------------------------------------------
>
> Key: NH-2596
> URL: http://216.121.112.228/browse/NH-2596
> Project: NHibernate
> Issue Type: Bug
> Components: Core
> Affects Versions: 3.0.0.Alpha3
> Reporter: Filip Kinsky
> Priority: Major
> Attachments: NHListenerTest.zip, NHListenerTest_NH31.zip
>
>
> We're logging modification date in few of our persisted classes using simple
> interface and basic IPreInsert/UpdateEventListener implementation which uses
> this code to set LastModified field:
> var trackable = entity as ITrackModificationDate;
> if (trackable != null)
> {
> trackable.LastModified = DateTime.Now;
> persister.SetPropertyValue(state, "LastModified", trackable.LastModified);
> }
> This works for basic classes without any inheritance hierarchy, but when I
> map inherited classes (LastModified field implemented by the hierarchy
> root) and update some property which exists just in the inherited class, the
> listener is triggered, but the modified LastModified property value is not
> being persisted into database. I isolated the problem and implemented
> attached failing test, but I'm not able to figure out what should I do in
> the listener to force NH to update the DB properly.
> Test classes:
> public class Thing : ITrackModificationDate
> {
> public virtual long Id { get; set; }
> public virtual DateTime LastModified { get; set; }
> }
> public class InheritedThing: Thing
> {
> public virtual string SomeText { get; set; }
> }
> public class ThingMap : ClassMap<Thing>
> {
> public ThingMap()
> {
> Id(x => x.Id).GeneratedBy.Assigned();
> Map(x => x.LastModified);
> }
> }
> public class InheritedThingMap: SubclassMap<InheritedThing>
> {
> public InheritedThingMap()
> {
> Map(x => x.SomeText);
> }
> }
> Failing test:
> [Fact]
> public void InheritedThing_LastModified_Should_BeSetOnUpdate()
> {
> var t = new InheritedThing {Id = 1, SomeText = "aa"};
> session.Save(t);
> session.Flush();
> session.Clear();
>
> Thread.Sleep(1000);
> t = session.Get<InheritedThing>(1L);
> t.SomeText = "bb";
> session.Update(t);
> session.Flush();
> session.Clear();
>
> t = session.Get<InheritedThing>(1L);
> Assert.True(DateTime.Now.Subtract(t.LastModified).TotalSeconds < 1); //this fails - LastModified property isn't updated in DB
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://216.121.112.228/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
|