Julian Jelfs’ Blog

NHibernate – Setters of lazy classes cannot be final

Posted in NHibernate by julianjelfs on March 27, 2009

I noticed when running unit tests that I was getting the following error written to the console when building the NHibernate session factory:

2009-03-11 08:47:00,843 ERROR 7 NHibernate.Tuple.Entity.PocoEntityTuplizer – Setters of lazy classes cannot be final

What is curious here is that this is being logged as an error and yet everything is working fine. So what is going on?

The reason this error is logged is because when building the session factory nhibernate checks that each property is proxeable and, for various reasons it can conclude that it is not. In my case, the setter on the property is private. So far this seems to make sense. What is unclear to me is that if the setter is private and NHibernate is logging an error saying it cannot proxy the property, how come it works? My worry is that because Nhibernate cannot directly set the property it is forced to use reflection and therefore I am paying some performance penalty.

My “solution” is to simply make the property setter public (though protected or internal will do). This makes the error go away and I’m relatively comfortable with it because in reality my code deals with the interface which does not have a setter at all and so I’m not really exposing more data than I was before.

I would like ot have a clearer understanding of what is going on here though.

Advertisements
Tagged with:

3 Responses

Subscribe to comments with RSS.

  1. Harry M said, on July 9, 2009 at 2:23 pm

    Yeah. We’ve got it happening too. Pretty strange.

  2. david said, on November 2, 2010 at 4:24 pm

    Hi,

    i think I can see a problem with this, but maybe I am wrong.

    if your paged record set has 50 results, but atleast every second result is a duplicate, when you display the 50 results, there will be only 25 do display ? Is this the case in the scenario you describe above?

    • julianjelfs said, on November 5, 2010 at 10:00 am

      I don’t think so because this doesn’t occur when actually running queries. Rather it happens when building the session factory when nhibernate is going through checking that the mappings and the domain objects they refer to all make sense.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: