Last chance update events on entity

2 views
Skip to first unread message

Graham Bunce

unread,
Jul 13, 2009, 1:08:50 PM7/13/09
to nhusers
All,

I've implemented a base entity class that all my business entities
inherit from. What I need to do is to add events that this common
class raises when certain things happen on it (e.g. CRUD style stuff).
There is business logic that takes place on (e.g.) create of an
entity.

I was thinking of adding events to the base entity that could be
hooked into by inheriting business logic and then this base class
hooking into the NH event system (IPreUpdateEventListener,
IPreInsertEventListener).

This business logic is unknown by me (as I'm developing a framework
for extending later by different projects). However, this business
logic could easily be updating entity data (e.g On save, check the
time, set a Late Action flag) but this will never get saved as by the
point NH raises the events I'm hooked into I MUST change the state
object. My business classes are not aware of this, nor am I able to
make them so.

Any ideas? Is there any NH event I can use that will let me change the
object data itself and still have this propagated down to the database
through NH?

Fabio Maulo

unread,
Jul 13, 2009, 1:28:36 PM7/13/09
to nhu...@googlegroups.com
Pre* events

2009/7/13 Graham Bunce <graha...@hotmail.com>



--
Fabio Maulo

Fabio Maulo

unread,
Jul 13, 2009, 1:30:44 PM7/13/09
to nhu...@googlegroups.com
But it is not so easy if you don't know what people will do with it.
You should maintain that logic inside your code before call NH.

In practice who use nh's events should know how NH work, should know how use cascade etc.

2009/7/13 Fabio Maulo <fabio...@gmail.com>



--
Fabio Maulo

Fabio Maulo

unread,
Jul 13, 2009, 1:44:01 PM7/13/09
to nhu...@googlegroups.com
About events usage I would write a post but really is hard because what you can do and what you can't do is really long to explain.
NH's events are not as common events in .NET... In .NET you may have a class doing something and raising events for some actions.
NH's events are NH itself; all the persistent work is done through listeners and for that reason who write a listener should know how NH work/think.
I saw some issue, reported as bug, about collection initialization... well a collection shouldn't be initialized inside a listener because not initialized collection will not be processed. If you initialize a collection during Flush, for us, something wrong happened in NH and not in your custom event. If you really want do it you should override the listener where NH is checking de collection state during flush and not only a Pre* listener.

2009/7/13 Fabio Maulo <fabio...@gmail.com>



--
Fabio Maulo
Reply all
Reply to author
Forward
0 new messages