Skip to content

NH-2873 - NH3.2.0: public virtual getter & backend field Options  #1245

@nhibernate-bot

Description

@nhibernate-bot

Kristof Riebbels created an issue — 6th September 2011, 13:06:54:

When using a backing field,

You not always get the result of the backing field.

  • Somethimes I use the nullpattern in Nhibernate, that worked beautifully in NH2.1, but not in NH3.2
  • also, when you have a private or protected backing field, with just a public virtual Property that returns the backing field, it gives a nullrefence exceptions...

It does not happen when Lazy = false. So it's only like this when a proxy is genereated.
I've managed to recreate the problem in a test, although i found it not that easy.

Also, another fault is happening when cleaning the database, see the test: CannotRemoveDomainClass

Please advice.

Thx,


Kristof Riebbels added a comment — 6th September 2011, 14:54:53:

Example of debugging the real life session with code sample and mapping. Just extra information.


Tom Marien added a comment — 10th September 2011, 13:42:08:

Nullpattern works see nhusers post, but test you supplied is strange, because lazy properties only work with auto properties, even the mapping validator should throw an exception.


Kristof Riebbels added a comment — 12th September 2011, 8:06:34:

This is one gives a better idea of a more reallife example.

But this is not with a backend field.

In the NHusers forum http://groups.google.com/group/nhusers/browse_frm/thread/f05aa549745db26e

it has been suggested that lazy properties are only for autoproperties and not for something else. => Is this true?

But check this project out. Set lazy to true => everything fails.

<!--To fix the tests: just uncomment this and comment the one below this => differnce: lazy=false must be true-->
    <!--<property name="NickName" length="25" type="string" column="nickname" access="property" lazy="false" />-->
    <property name="NickName" length="25" type="string" column="nickname" access="property" lazy="true" />

Kristof Riebbels added a comment — 23rd November 2011, 10:09:19:

I have been debugging this quite deep and it seems to be related to the DefaultDynamicLazyFieldInterceptor.

But what I find very strange is ,that when NHibernate flushes the same object, the proxy returns to interceptor the right field.
But when you load the object and ask the field though the property it just fails.

The bug also occurs when:

<many-to-one name="Partner" class="Person" access="property" column="partnerId"  cascade="none" foreign-key="FK*Person*Partner" lazy="no-proxy" /> not when it is:
<many-to-one name="Partner" class="Person" access="property" column="partnerId"  cascade="none" foreign-key="FK*Person*Partner" lazy="proxy" />

if you however map the field as the following in code

    <set name="Cats" access="property" lazy="extra" cascade="all-delete-orphan" inverse="true" >
      <key foreign-key="master" column="masterId"  />
      <one-to-many class="Cat" />
    </set>

with corresponding code: (not pretty code)

        public virtual IEnumerable<Cat> Cats
        {
            get { return cats; } set{cats = (ISet<Cat>) value;}
        }

then it also works.

it seems to me (but who am I) that the bug is in the proxy building. When the set accessor is used, nhibernate uses the property set accessor and not the field accessor. The property set accessor triggers the interceptor where the field set accessor does not.

If someone is able to help debugging this..., I'm glad to absorb the knowlegde :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions