Hi everyone,

took me a while to figure out the problem but now my question is most
of all if there is a reason to it :-)

The problem is that when loading an Image object and the associated
User object is loaded, the Set inside a component mapping does not
respect the lazy-property, i.e. the associated Ratings are always
loaded. Not so, if I simply load the User: then lazy is respected. Is
this a bug or expected behaviour?

My classes look something like this:

class Image {
    public User User { get; set; }
}

class User{
    public virtual RatingList Ratings { get; set; }
}

Mappings:

<class name="Image" table="Images" lazy="false">
        <many-to-one name="User" column="UserId" class="User" lazy="proxy" />
</class>

<class name="User" table="[User]" lazy="true">
        <component name="Ratings">
                <set name="Items" table="Ratings" inverse="true" generic="true"
lazy="true" where="3 > Status" >
                        <key column="UserId" />
                        <one-to-many class="Rating" />
                </set>
        </component>
</class>

The component mapping is kind of a hack because it allows us to use a
custom List type in our Domain while being fully compatible with
NHibernate. RatingList implements a generic List which contains:

private ISet<T> _persistentItems = new HashedSet<T>();
private ISet<T> Items
{
    get
    {
        _persistentItems.Clear();
        _persistentItems.AddAll(this);
        return _persistentItems;
    }
    set
    {
        _persistentItems = value;
        Clear();
        AddRange(value);
    }
}

Only today I found a maybe better solution here:
http://blog.petegoo.com/archive/2008/01/10/nhibernate-custom-user-types-and-collections.aspx,
but am not ready to implement it (yet).

Cheers, Oliver
-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to