Hello,

I trying some code here with NHibernate 2.0.1 and sundelly I noticed
this behaviour:

When I try to load and object from database using a just simple HQL it
works. But, if instead I try to use ISession.Load<T> method, an
exception is thrown.

here is the code with HQL:

        public override Cliente GetById(int id)
        {
            string hql = @"from Cliente as cli
                           where cli.Id = :codigo";

            using (ISession sessao = NHelper.GetCurrentSession())
            using (ITransaction tx = sessao.BeginTransaction
(IsolationLevel.ReadCommitted))
            {
                Cliente cliente = sessao.CreateQuery(hql).SetInt32
("codigo", id).UniqueResult<Cliente>();
                tx.Commit();
                return cliente;
            }
        }

and here is the code with ISession.Load<T> method:

        public override Cliente GetById(int id)
        {
            using (ISession sessao = NHelper.GetCurrentSession())
            using (ITransaction tx = sessao.BeginTransaction
(IsolationLevel.ReadCommitted))
            {
                Cliente cliente = sessao.Load<Cliente>
(id).UniqueResult<Cliente>();
                tx.Commit();
                return cliente;
            }
        }


My doubt is that:

if both approachs uses the mapping file as reference to map the
resultset to object, why is the .Load<T> method throwing the
exception: Could not load the proxy. No session. ?

Thanks in advance.

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