I have some HQL to left join fetch an optional, primary-key-style one-
to-one association.  My mappings are textbook (see
http://nhforge.org/doc/nh/en/index.html#mapping-declaration-onetoone
and how the Employee and Person both have one-to-one's setup with the
'younger sibling' using an Id generation strategy of fetch).  This
works great when using an ISession, but when I use an
IStatelessSession, I get this error:

System.InvalidCastException: Unable to cast object of type
'NHibernate.Impl.StatelessSessionImpl' to type 'NHibernate.ISession'.
at NHibernate.Id.ForeignGenerator.Generate(ISessionImplementor
sessionImplementor, Object obj)
at NHibernate.Impl.StatelessSessionImpl.Insert(String entityName,
Object entity)
at NHibernate.Impl.StatelessSessionImpl.Insert(Object entity)

I'm currently on 2.1.2.GA, but I noticed the same presumptuous down-
cast from ISessionImplementor to ISession in the latest version
(https://github.com/nhibernate/nhibernate-core/blob/master/src/
NHibernate/Id/ForeignGenerator.cs).

I've tried all kinds of other mappings, all of which annoyingly just
don't work (either it always fetches as null even when it finds a
sibling, or will return a Proxy when it should return null).  Not sure
if 2.1.2.GA is biting me for alternatives.

Our current workaround is to use the mapping that returns the Proxy
when it doesn't find the sibling, and then set it to null if we detect
the Proxy (if it "is" an INHibernateProxy).

Any ideas of how to do this cleanly would be much appreciated,
Ross

-- 
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