From: Filip K. (JIRA) <nh...@gm...> - 2011-03-25 14:13:57
|
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 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 |
From: Filip K. (JIRA) <nh...@gm...> - 2011-03-25 14:21:04
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20739#action_20739 ] Filip Kinsky commented on NH-2596: ---------------------------------- This problem was discussed on http://groups.google.com/group/nhusers/browse_thread/thread/7fab248b11a083cb/ec83f5a920caaabf , but without any result. I'm running NH 3.0.0.1003 - is it possible that it's fixed in NH 3.1 GA? I wasn't able to upgrade yet unfortunately.. > 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 > > 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 |
From: Fabio M. (JIRA) <nh...@gm...> - 2011-03-25 16:44:59
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20740#action_20740 ] Fabio Maulo commented on NH-2596: --------------------------------- FYI you are running 3.0.0Alpha3 > 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 > > 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 |
From: Fabio M. (JIRA) <nh...@gm...> - 2011-03-25 16:47:04
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20741#action_20741 ] Fabio Maulo commented on NH-2596: --------------------------------- and the impl. of your listeners ? and the transaction ? > 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 > > 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 |
From: Filip K. (JIRA) <nh...@gm...> - 2011-03-28 07:03:19
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Filip Kinsky updated NH-2596: ----------------------------- Attachment: NHListenerTest.zip solution with listener implementation and failing test (InheritedThing_LastModified_Should_BeSetOnUpdate) > 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 > > > 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 |
From: Filip K. (JIRA) <nh...@gm...> - 2011-03-28 07:05:24
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20770#action_20770 ] Filip Kinsky commented on NH-2596: ---------------------------------- I'll try to upgrade the test solution I've just uploaded to NH 3.1 to see if it isn't already solved. Will report back soon... > 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 > > > 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 |
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 |
From: Filip K. (JIRA) <nh...@gm...> - 2011-03-28 07:24:24
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20772#action_20772 ] Filip Kinsky commented on NH-2596: ---------------------------------- so the result is the same when I upgraded the test solution to NH 3.1 GA version - the test still fails > 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 |
From: Fabio M. (JIRA) <nh...@gm...> - 2011-03-28 18:04:22
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Fabio Maulo closed NH-2596. --------------------------- Resolution: Not an Issue pre-insert and pre-update listeners are not intended to be used to change the values of the entity. Instead they should be used to check-values (for that reason they return "veto"). For what you want achieve you have to implement a ISaveOrUpdateEventListener that in your case is: public void OnSaveOrUpdate(SaveOrUpdateEvent @event) { var trackable = @event.Entity as ITrackModificationDate; if (trackable != null) { trackable.LastModified = CurrentDateTimeProvider(); } } Then you have to register it as (in your case): cfg.EventListeners.SaveEventListeners = new[] { listener }.Concat(cfg.EventListeners.SaveEventListeners).ToArray(); cfg.EventListeners.SaveOrUpdateEventListeners = new[] { listener }.Concat(cfg.EventListeners.SaveOrUpdateEventListeners).ToArray(); cfg.EventListeners.UpdateEventListeners = new[] { listener }.Concat(cfg.EventListeners.UpdateEventListeners).ToArray(); That is all. > 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 |
From: Filip K. (JIRA) <nh...@gm...> - 2011-03-28 19:38:28
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20780#action_20780 ] Filip Kinsky commented on NH-2596: ---------------------------------- The suggested solution unfortunately works just when entity is saved explicitely using Session.Save/Update/SaveOrUpdate. It doesn't work in case the entity is tracked by the session and saved implicitely on session.Flush like in this case: using(var session = sessionFac.OpenSession()) { var e = session.Load<MyEntity>(123); e.Name = "new name"; } Save/Update/SaveOrUpdateEventListeners aren't fired in this scenario AFAIK. So there's no fully working solution to the problem at the moment in my opinion if I'm not wrong? > 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 |
From: Fabio M. (JIRA) <nh...@gm...> - 2011-03-28 20:11:28
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20781#action_20781 ] Fabio Maulo commented on NH-2596: --------------------------------- So you have to implements even IFlushEntityEventListener: public void OnFlushEntity(FlushEntityEvent @event) { if(@event.EntityEntry.Status == Status.Deleted) { return; } var trackable = @event.Entity as ITrackModificationDate; if (trackable != null) { trackable.LastModified = CurrentDateTimeProvider(); } } The register line is cfg.EventListeners.FlushEntityEventListeners = new[] { listener }.Concat(cfg.EventListeners.FlushEntityEventListeners).ToArray(); If you have other questions please use the nhusers google group. Thanks. > 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 |
From: Filip K. (JIRA) <nh...@gm...> - 2011-03-28 20:29:26
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20784#action_20784 ] Filip Kinsky commented on NH-2596: ---------------------------------- Thanks for your suggestion - I'll try it asap. And sorry for this "not an issue" issue - I really thought it's IPre*Listener bug.. > 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 |
From: Fabio M. (JIRA) <nh...@gm...> - 2011-04-02 21:41:34
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20820#action_20820 ] Fabio Maulo commented on NH-2596: --------------------------------- Don't worry, there is no problem. > 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 |
From: Scott F. (JIRA) <nh...@gm...> - 2011-04-06 07:56:52
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=20835#action_20835 ] Scott Findlater commented on NH-2596: ------------------------------------- Fabio, I rasied NH-2617 which was closed with this being a duplicate - sorry about that. However, I still don't feel I have a conclusion. You say "pre-insert and pre-update listeners are not intended to be used to change the values of the entity. Instead they should be used to check-values (for that reason they return "veto")." but how come if an inherited entity which has just 1 property modified prior to the PreUpdate listener, will have all modifications made within the PreUpdate listener persisted to the database (even with dynamic-update set to true) vs an inherited entity which only has properties modified within the PreUpdate listener will not result in changes being persisted? Does this behaviour not demonstrate an issue in NHibernate where entity's modified within PreUpdate listeners can change data and behave correctly? Also Ayende's very popular audit trail blog post which uses PreUpdate and PreInsert listeners (http://ayende.com/Blog/archive/2009/04/29/nhibernate-ipreupdateeventlistener-amp-ipreinserteventlistener.aspx) - does that mean this approach is wrong? This is not intended to be a complaint at NHibernate, just I really want to understand the event model correctly. > 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 |
From: Filip K. (JIRA) <nh...@gm...> - 2011-05-11 12:03:08
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21051#action_21051 ] Filip Kinsky commented on NH-2596: ---------------------------------- continuation of this issue: https://groups.google.com/d/topic/nhusers/0kugoXFPeGw/discussion > 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 |
From: Fabio M. (JIRA) <nh...@gm...> - 2011-05-11 13:45:06
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21054#action_21054 ] Fabio Maulo commented on NH-2596: --------------------------------- The register line is cfg.EventListeners.FlushEntityEventListeners = new[] { listener }.Concat(cfg.EventListeners.FlushEntityEventListeners).ToArray(); > 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 |
From: Filip K. (JIRA) <nh...@gm...> - 2011-05-11 13:53:02
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21055#action_21055 ] Filip Kinsky commented on NH-2596: ---------------------------------- sorry Fabio, but I don't understand what do you mean by this comment - I registered the listener in the same manner as you can see from this code: https://github.com/Buthrakaur/NHListenerTests/blob/master/NHListenerTest/SetModificationTimeSaveOrUpdateEventListener.cs#L110 > 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 |
From: Fabio M. (JIRA) <nh...@gm...> - 2011-05-11 14:12:05
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21057#action_21057 ] Fabio Maulo commented on NH-2596: --------------------------------- 1) your IFlushEntityEventListener inherits from default. Have you a special reason ? 2) where is the line I have sent you? you are appending after default listener I'm inserting before. btw, If you want an example send me the code as attach in a private mail, then I will use your domain to write a public example. > 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 |
From: Filip K. (JIRA) <nh...@gm...> - 2011-05-11 14:20:43
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21058#action_21058 ] Filip Kinsky commented on NH-2596: ---------------------------------- I see - you're right... > 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 |
From: Filip K. (JIRA) <nh...@gm...> - 2011-05-11 17:24:04
|
[ http://216.121.112.228/browse/NH-2596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21061#action_21061 ] Filip Kinsky commented on NH-2596: ---------------------------------- fully working IFlushEntityEventListener can be found here: https://github.com/Buthrakaur/NHListenerTests/blob/master/NHListenerTest/SetModificationTimeFlushEntityEventListener.cs > 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 |