Update on this: my integration test was using an IStatelessSession to
save the data to the database before the HQL selected it, and the
IStatelessSession save was the one throwing the error (as seen be the
stack I posted).  If I changed my test to setup the data using an
ISession, I get beyond the exception, but I still can't eagerly fetch
the associated data as it returns null.  Looking at the logs, I see
NHibernate finding the appropriate data, hydrating the entity,
resolving the association, and then materializing the entity, yet the
property containing the associated data is still null.

I see 2 issues:
- cannot save an entity with foreign generated Id with an
IStatelessSession
- cannot left join fetch in HQL a primary-key-style one-to-one
association with an IStatelessSession (also recreated using direct
SQL).

Any ideas?

Thanks,
Ross

On Apr 12, 3:53 pm, Ross Beehler <[email protected]> wrote:
> I have some HQL to left join fetch an optional, primary-key-style one-
> to-one association.  My mappings are textbook 
> (seehttp://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