I ran in this exact same issue.

You cannot use the generic version of Load in combination with
specifying a proxy for your class.
If you think about it for a second, it does make sense.

The generated proxy does not implement (override) your mapped class.
It implements the proxy you specified.

When using the generic version of Load. It tries to cast to your
entity type so it will fail with an invalid cast exception.

You should use the non-generic version of Load when you specify a
proxy for your class (session.Load(typeof(Skill), 42)).
You will get a proxied class implementing INHibernateProxy and ISkill.




On 30 sep, 07:16, Richard Dingwall <[email protected]> wrote:
> I have the following class and mapping:
>
> public interface ISkill : IObjectWithId<int> {...}
> public class Skill : ISkill, ObjectWithId<int>, IEquatable<Skill>
> {...}
>
> <class name="Skill" table="Skill"proxy="ISkill">...</class>
>
> Skill has a few collections but no subclasses.
>
> Fetching skills via Session.Get<T>() works great, but callingLoad()
> always throws an internal NH exception:
>
> ISkill skill = Session.Load<Skill>(42);
>
> System.InvalidCastException : Unable to cast object of type
> 'INHibernateProxyProxy' to type 'Abc.DomainModel.Xyz.Skill'.
> at NHibernate.Impl.SessionImpl.Load[T](Object id)
>
> It's maybe (probably) something really dumb I am doing, but is this
> not a massive flaw?
>
> Why bother having a generic version ofLoad() if it doesn't support
> lazy loading, its primary use case? Could we get a more useful error
> message at least?
>
> Using NH 2.1.0.GA. I tried with LinFu, Spring and Castle and all
> implementations had the same result.
>
> The other alternative, specifying theproxydoesn't work either,
> because it is aproxynot a mapped class and NH doesn't recognize
> querying by proxies.
>
> ISkill skill = Session.Load<ISkill>(42); // cannot resolve unmapped
> class 'ISkill'
>
> Someone please explain where I am going wrong here!
>
> Rich
--~--~---------~--~----~------------~-------~--~----~
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