Error calling IStatelessSession.Update

551 views
Skip to first unread message

Jordan

unread,
Apr 30, 2012, 10:22:24 AM4/30/12
to nhusers
Hi all,

I've got a problem doing updates with a stateless session and I'm
wondering if anyone has seen something like this. (NHibernate 3.1).

I'm basically doing the following:

SomeEntity e = statelessSession.Get<SomeEntity>(id);
e.SomeProperty = "a new value";
statelessSession.Update(e);

and I am getting the following error:

NHibernate.MappingException: No persister for:
Castle.Proxies.SomeEntityProxy
at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String
entityName)
at NHibernate.Impl.StatelessSessionImpl.GetEntityPersister(String
entityName, Object obj)
at NHibernate.Impl.StatelessSessionImpl.Update(String entityName,
Object entity)
at NHibernate.Impl.StatelessSessionImpl.Update(Object entity)

I have stepped through in the debugger and can see that
statelessSession.Get<SomeEntity>(id) is returning me a proxy. Is this
correct?


regards,
Jordan.

Jordan

unread,
Apr 30, 2012, 11:47:00 AM4/30/12
to nhusers
Ok - upon further investigation there is some weird behaviour here.

I have changed my code to retrieve 2 entities of different types with
IStatelessSession.Get<T>().

For one of them it correctly returns a non-proxy instance of T (and
updates therefore work), but for the other it always gives me a proxy.

I would have thought it should never return a proxy?

regards,
Jordan.

Alex Vilela

unread,
Apr 30, 2012, 12:51:52 PM4/30/12
to nhu...@googlegroups.com
Hi Jordan,

AKAIK the proxy is related to whether you want to lazy load your entity properties and not whether you want to use the first/second level cache (a stateless session).

Alex Vilela


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.


Jordan

unread,
May 1, 2012, 4:53:27 AM5/1/12
to nhusers
Hi Alex,

But in a stateless session there is no lazy loading, and no cache.
That is is the whole point of a stateless session.

(see docs: http://docs.jboss.org/hibernate/orm/3.3/api/org/hibernate/StatelessSession.html
and question about lazy loading http://www.mail-archive.com/nhu...@googlegroups.com/msg12715.html)

I have tracked this down to what looks like a very weird bug. If you
mark one of the properties of an entity with lazy="no-proxy", then the
entity itself is returned as a proxy when you call
IStatelessSession.Get<T>();

regards,
Jordan.


On Apr 30, 5:51 pm, Alex Vilela <alexvil...@gmail.com> wrote:
> Hi Jordan,
>
> AKAIK the proxy is related to whether you want to lazy load your entity
> properties and not whether you want to use the first/second level cache (a
> stateless session).
>
> Alex Vilela
>
Reply all
Reply to author
Forward
0 new messages