-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Remoting problem with NHibernate
PostPosted: Fri Dec 02, 2005 12:48 pm 
Newbie

Joined: Wed Nov 16, 2005 10:06 pm
Posts: 4
I'm using .Net remoting for all my projects in order to disconnect direct database access from the end user, and in order to support a variety of clients. I'm using NHibernate in the remote data layer in order to take advantage of ORM. The remote objects that utilize NHibernate are hosted in a Windows service app.

I've noticed that lists of objects (IList) returned from queries do not reflect changes to the back-end database (SQL) unless the Windows service is stopped and restarted (objects reloaded). I would guess this is due to NHibernate caching the data. Does NHibernate cache all data by default? If so, how can I turn that off - I don't want any caching whatsoever.

Next, when I retrieve a particular object, make some changes, and attempt and update via the a remote object method using NHibernate's Update method, I get an error:

"a different object with the same identifier value was already associated with the session: 2, of class: Cbca.Crm.Dcl.CrmIssue"

I suspect the remote instance of an NHibernate session is again caching the object, then trying to update with the disassociated object I sent back to update, thus resulting in the conflict. This error does not occur when not using .Net remoting.

Can anyone suggest the best way to handle this situation? Will turning off all caching cure all my ills?

Thanks,
Stoked.

Current NHibernate config section:

<nhibernate>
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="hibernate.connection.connection_string" value="Server=usia2k02;initial catalog=warehouse;Integrated Security=SSPI" />
<add key="hibernate.query.substitutions" value="true 1, false 0, yes 'Y', no 'N'" />
</nhibernate>


Top
 Profile  
 
 Post subject: Remoting problem with NHibernate
PostPosted: Fri Dec 02, 2005 1:49 pm 
Newbie

Joined: Wed Nov 16, 2005 10:06 pm
Posts: 4
Okay, I figured out that using a SaveOrUpdateCopy will save my disconnected object and update the database. However, if I then change the record via another app, then retrieve the object again, the change is not apparent. I assume this is because the object is still cached and not refreshed when I retrieve it.

In the remote layer, I'm trying to increase performance by using a static session instance (see http://www.theserverside.net/articles/s ... ibernateP2), reconnecting and disconnecting in each data access method. Is this bad design for remoting? Should a new session always be created then closed?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 7:13 am 
Hi

Did you already take a look at Martin Fowlers Enterprise Patterns ? If not, I recommend you look at Identity Map, Unit Of Work and Optimistic Offline Lock. These patterns address your problem.

Gernot


Top
  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 10:55 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Using long-living sessions is not recommended; sessions are not exception-proof and you get all these problems about its cache, concurency access, etc.

And about Caches, you may read the second-level caches documentation.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.