Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate: Meaning of interceptors return value

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.

like image 468
anonymous Avatar asked May 12 '09 20:05

anonymous


1 Answers

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.

like image 109
Steve Willcock Avatar answered Nov 04 '22 20:11

Steve Willcock