Reputation: 6885
I think this is an easy question, but my googling is weak on this.
I had the problem described in the following link with regard to a generated ID and cascading:
https://www.hibernate.org/hib_docs/nhibernate/html/example-parentchild.html (towards the bottom)
I fixed it using their suggested method of an Interceptor. Everything appears to be working, so I am happy.
That said, I have no idea what the significance of the return value is from methods such as:
public override bool OnLoad(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
if (entity is Persistent) ((Persistent)entity).OnLoad();
return false;
}
public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
if (entity is Persistent) ((Persistent)entity).OnSave();
return false;
}
In both cases false is returned.
When I google about NHibernate Interceptors I see plenty of examples of how to write one. Some instead return true (http://www.lostechies.com/blogs/rhouston/archive/2008/03/27/creating-a-timestamp-interceptor-in-nhibernate.aspx). I have no idea what the difference is here. My code is working, but Interceptors seem useful to me so I'd like to have a better understanding.
Upvotes: 7
Views: 2022
Reputation: 26849
I believe the return value should indicate if the state parameter has been changed in the interceptor method. You're right - it's a tough one to google at the moment - the NHibernate site moved recently and google doesn't seem to find as much useful info as it used to.
Upvotes: 5
Reputation: 725
Huey,
Read this post, i'm not a .net programmer, but this post is very usefull:
http://knol.google.com/k/fabio-maulo/nhibernate-chapter-11/1nr4enxv3dpeq/14#
Chapter 11. Interceptors and events It is often useful for the application to react to certain events that occur inside NHibernate. This allows implementation of certain kinds of generic functionality, and extension of NHibernate functionality.
11.1. Interceptors The IInterceptor interface provides callbacks from the session to the application allowing the application to inspect and/or manipulate properties of a persistent object before it is saved, updated, deleted or loaded. One possible use for this is to track auditing information. For example, the following IInterceptor automatically sets the createTimestamp when an IAuditable is created and updates the lastUpdateTimestamp property when an IAuditable is updated.
Hope it enlight you a little more.
Upvotes: 0