Issues when using stateless session to update entities with optimistic concurrency

639 views
Skip to first unread message

Paul Batum

unread,
Feb 2, 2010, 7:13:55 PM2/2/10
to nhusers
Hi all,

I am having trouble with using stateless session to perform updates.
Basically, the problem is that during the generation of the prepared
statement for the update, NH tries to read the version from a proxy,
and I get the "proxies cannot be fetched by a stateless session"
error.

My code is something along these lines:

using (var session = sessionFactory.OpenStatelessSession
())
using (var tx = session.BeginTransaction())
{
var results = session.CreateCriteria<PaymentDetail>()
// do some filtering
.List<PaymentDetail>();

foreach (var paymentDetail in results)
{
paymentDetail.SomeProperty = "123456"
session.Update(paymentDetail);
}

tx.Commit();
}

In this example, PaymentDetail has a many-to-one to Payment. You can
see in the stack trace below that the error occurs because it tries to
initialize the Payment proxy as part of getting the version for
Payment.

NHibernate.SessionException: proxies cannot be fetched by a stateless
session
at NHibernate.Impl.StatelessSessionImpl.ImmediateLoad(String
entityName, Object id)
at NHibernate.Proxy.AbstractLazyInitializer.Initialize()
at NHibernate.Proxy.AbstractLazyInitializer.GetImplementation()
at NHibernate.ByteCode.Castle.LazyInitializer.Intercept(IInvocation
invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.PaymentProxy.get_Version()

System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation.
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object
[] arguments, ref SignatureStruct sig, MethodAttributes
methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[]
arguments, Signature sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture,
Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo
culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[]
index)
at NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object
target)

NHibernate.PropertyAccessException: Exception occurred getter of
XXX.Domain.EntityBase.Version
at NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object
target)
at NHibernate.Tuple.Entity.AbstractEntityTuplizer.GetVersion(Object
entity)
at NHibernate.Persister.Entity.AbstractEntityPersister.GetVersion
(Object obj, EntityMode entityMode)
at NHibernate.Persister.Entity.AbstractEntityPersister.IsTransient
(Object entity, ISessionImplementor session)
at NHibernate.Engine.ForeignKeys.IsTransient(String entityName, Object
entity, Nullable`1 assumed, ISessionImplementor session)
at NHibernate.Engine.ForeignKeys.GetEntityIdentifierIfNotUnsaved
(String entityName, Object entity, ISessionImplementor session)
at NHibernate.Type.EntityType.GetIdentifier(Object value,
ISessionImplementor session)
at NHibernate.Type.ManyToOneType.NullSafeSet(IDbCommand st, Object
value, Int32 index, Boolean[] settable, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate
(Object id, Object[] fields, Object rowId, Boolean[] includeProperty,
Boolean[][] includeColumns, Int32 table, IDbCommand statement,
ISessionImplementor session, Int32 index)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object
id, Object[] fields, Object[] oldFields, Object rowId, Boolean[]
includeProperty, Int32 j, Object oldVersion, Object obj,
SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert
(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean
[] includeProperty, Int32 j, Object oldVersion, Object obj,
SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object
id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection,
Object[] oldFields, Object oldVersion, Object obj, Object rowId,
ISessionImplementor session)
at NHibernate.Impl.StatelessSessionImpl.Update(String entityName,
Object entity)
at NHibernate.Impl.StatelessSessionImpl.Update(Object entity)


Is there anything in particular I need to be aware of when using a
stateless session with objects that have optimistic concurrency? The
only work around I can figure out at this stage is to eager fetch a
really large chunk of the graph (payment and various other associated
entities) - but this will be really slow and defeat much of the
purpose of using stateless session. I actually don't even care about
the optimistic concurrency for this operation and it would be great if
I could tell the session "just ignore the version" but there doesn't
seem to be a way to do that.

Thanks,

Paul Batum

Paul Batum

unread,
Feb 4, 2010, 6:33:32 PM2/4/10
to nhusers
Bump!

I really don't know what to do about this, and I've been unable to
make any further progress on the issue.

Any ideas, anyone?

Paul Batum

On Feb 3, 11:13 am, Paul Batum <paul.ba...@gmail.com> wrote:
> Hi all,
>

> I am having trouble with usingstatelesssessionto perform updates.


> Basically, the problem is that during the generation of the prepared
> statement for the update, NH tries to read the version from a proxy,
> and I get the "proxies cannot be fetched by astatelesssession"
> error.
>
> My code is something along these lines:
>

>             using (varsession= sessionFactory.OpenStatelessSession


> ())
>             using (var tx =session.BeginTransaction())
>             {

>                 var results =session.CreateCriteria<PaymentDetail>()

> ISessionImplementorsession, Int32 index)


> at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object
> id, Object[] fields, Object[] oldFields, Object rowId, Boolean[]
> includeProperty, Int32 j, Object oldVersion, Object obj,
> SqlCommandInfo sql, ISessionImplementorsession)
> at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert
> (Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean
> [] includeProperty, Int32 j, Object oldVersion, Object obj,
> SqlCommandInfo sql, ISessionImplementorsession)
> at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object
> id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection,
> Object[] oldFields, Object oldVersion, Object obj, Object rowId,
> ISessionImplementorsession)
> at NHibernate.Impl.StatelessSessionImpl.Update(String entityName,
> Object entity)
> at NHibernate.Impl.StatelessSessionImpl.Update(Object entity)
>

> Is there anything in particular I need to be aware of when using astatelesssessionwith objects that have optimistic concurrency? The


> only work around I can figure out at this stage is to eager fetch a
> really large chunk of the graph (payment and various other associated
> entities) - but this will be really slow and defeat much of the

> purpose of usingstatelesssession. I actually don't even care about


> the optimistic concurrency for this operation and it would be great if

> I could tell thesession"just ignore the version" but there doesn't

Alexander Zaytsev

unread,
Jun 24, 2017, 1:38:39 AM6/24/17
to nhusers
7.5 years maybe not too late. 


Best Regards,
Alexander
Reply all
Reply to author
Forward
0 new messages