I don't understand your answer Fabio. Could you be more specific
please?

I don't care about the child collections, so if the StatelessSession
is ignoring them - great! That's what I wanted. But that still doesn't
tell me why the exception is occurring. This is what I don't
understand.

-Chris



On Sep 9, 3:56 pm, Fabio Maulo <[email protected]> wrote:
> http://nhforge.org/doc/nh/en/index.html#batch-statelesssession<http://nhforge.org/doc/nh/en/index.html#batch-statelesssession>"Collections
> are ignored by a stateless session."
> 2009/9/9 ChrisHolmes <[email protected]>
>
>
>
>
>
> > I'm having a problem using a StatelessSession and I don't understand
> > why. Hoping for some help here.
>
> > I've got a Movie entity that is mapped (fluently)  like so:
>
> > public class MovieMap : ClassMap<Movie>
> >    {
> >        public MovieMap()
> >        {
> >            Id(x => x.Id).UnsavedValue(0);
> >            Map(x => x.Title);
> >            Map(x => x.ReleaseYear);
> >            HasManyToMany(x => x.Directors)
> >                .FetchType.Select()
> >                .Table("MovieToDirector")
> >                .ParentKeyColumn("MovieId")
> >                .ChildKeyColumn("DirectorId");
> >            HasManyToMany(x => x.Actors)
> >                .FetchType.Select()
> >                .Table("MovieToActor")
> >                .ParentKeyColumn("MovieId")
> >                .ChildKeyColumn("ActorId");
> >            References(x => x.Genre).Column("GenreId").Not.LazyLoad
> > ().Fetch.Select();
> >        }
> >    }
>
> > As you can see, the Movie has sub-lists of Actors and Directors and
> > references a class called Genre. I'm fetching the list of movies from
> > the database and displaying them in a DataGrid like so:
>
> > private void LoadMovies()
> > {
> >            using (ITransaction tx = Session.BeginTransaction())
> >            {
> >                IList<Movie> movies = Session.CreateCriteria<Movie>
> > ().List<Movie>();
>
> >                if (movies.Count > 0)
> >                    movies = movies.OrderBy(x => x.Title).ToList();
>
> >                View.Movies = movies;
> >                tx.Commit();
> >            }
> > }
>
> > When I use a regular ISession, like above, it works fine. But I only
> > want to display the Movie entities and I am not displaying anything to
> > do with the child collections of Actor and Director. My thinking was
> > that if I used a StatelessSession, I would be able to do this...
>
> > However, when I change this from a ISession to a IStatelessSession, I
> > get an exception:
>
> >  ---> NHibernate.ADOException: could not execute query
> > [ SELECT this_.Id as Id2_0_, this_.Title as Title2_0_,
> > this_.ReleaseYear as ReleaseY3_2_0_, this_.GenreId as GenreId2_0_ FROM
> > dbo.[Movie] this_ ]
> > [SQL: SELECT this_.Id as Id2_0_, this_.Title as Title2_0_,
> > this_.ReleaseYear as ReleaseY3_2_0_, this_.GenreId as GenreId2_0_ FROM
> > dbo.[Movie] this_] -
> > --> NHibernate.AssertionFailure: possible non-threadsafe access to the
> > session
> >   at NHibernate.Engine.TwoPhaseLoad.InitializeEntity(Object entity,
> > Boolean readOnly, ISessionImplementor session, PreLoadEvent
> > preLoadEvent, PostLoa
> > dEvent postLoadEvent)
> >   at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList
> > hydratedObjects, Object resultSetId, ISessionImplementor session,
> > Boolean readOn
> > ly)
>
> > What I don't understand about this is that it is complaining of a
> > threading problem, but everything is happening on the same thread. And
> > the exact line error indicates this line:
>
> >  IList<Movie> movies = Session.CreateCriteria<Movie>().List<Movie>();
>
> > So I am not even getting to the point of ordering the movie list, or
> > displaying it to the screen. I am only changing one thing in this
> > code: I am changing the use from the Session to the StatelessSession,
> > and that is it.
>
> > Why is this happening and how can I fix it?
>
> > Thanks,
>
> > -Chris
>
> --
> Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
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