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.  [ 5 posts ] 
Author Message
 Post subject: Need help getting the architecture right
PostPosted: Fri Jun 15, 2007 3:47 pm 
Newbie

Joined: Tue Mar 13, 2007 9:00 pm
Posts: 5
Hi,

I've got a question about the best way to approach the follwoing: I've got an intergation application which runs as a windows service. For the bigger part it dos not require any user interation. However there is also a web interface (ASP.NET) that is that allows users to modify certain areas of the database. (same one as used by the windows service).

Now it is all running fine untill first the user adds a new record to a table and then the windows service application tries to add/modify a record in that exact same table - the nhibernate is thowing an exception on something along the lines of the Session is out of date. (do not remember the exact wording and it is very difficult to reproduce)

Now the way the applciation is written - there is a common class library that contains all of the mapping files / classes as well as the DAL classes, and it is shared for the two applciations. It contains a utility class that exposes an instance of ISessionFactory as a static property.

I was wondering is someone has a good workaround / solution for this kind of situation? (two applciations running separately trying to update the same database). Any help will be much appresiated (as I'm pioneering the use of NHibernate in the company that i work for - and if i do not find an elegant solution soon, the doors will be shut for the NHibernate use in the future).

Thanks in advance,
Nick Goloborodko

P.S. I'm on .NET 2.0, NHibernate 1.2 release.


Top
 Profile  
 
 Post subject: Re: Need help getting the architecture right
PostPosted: Fri Jun 15, 2007 3:56 pm 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
coolbest wrote:
Now it is all running fine untill first the user adds a new record to a table and then the windows service application tries to add/modify a record in that exact same table - the nhibernate is thowing an exception on something along the lines of the Session is out of date.


The same table or the same object? Let's say you have two records, A and B. If your Service tries to modify A but a user modifies B, do you have an issue?

coolbest wrote:
(do not remember the exact wording and it is very difficult to reproduce)


No log files? I would suggest configuring log4net to get some meaningful information. Can be hard to troubleshoot without it.

coolbest wrote:
I was wondering is someone has a good workaround / solution for this kind of situation? (two applciations running separately trying to update the same database).


Unless I'm missing something, this is basically a concurrency issue. I don't think it matters that your two applications are different. I have an application that is used by several people at the same time and they all update the same database.

Are you using a version property on your data objects? Either version or timestamp?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 8:20 pm 
Newbie

Joined: Tue Mar 13, 2007 9:00 pm
Posts: 5
Hi pelton,

Thanks for your quick reply. Here's my scenario - Say i've got a an object called Request which is persisted to table called RequestTable. First, the web applciation creates an object called Request and saves that to the database. Soon after my windows service application creates an instance of Request and when it tries to save it to the database the error is thrown.

The log4net worked for a while, but then it just died. Another mystery i just cannot get my head around.

In regards to the versions - i'm not sure. Not explicitly, unless NHibernate does that quitly in the background for me.

Thanks in advance,
Nick


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 6:16 am 
Beginner
Beginner

Joined: Wed Nov 08, 2006 8:24 am
Posts: 26
Location: Gothenburg, Sweden
Do you keep the session open all the time, or only when you actually are accessing the database? I would guess that hibernate could act a little funny if a session is open, and another session (e.g. the web interface) is accessing the database.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 11:34 am 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
coolbest wrote:
Say i've got a an object called Request which is persisted to table called RequestTable. First, the web applciation creates an object called Request and saves that to the database. Soon after my windows service application creates an instance of Request and when it tries to save it to the database the error is thrown.


Okay.

You say this is hard to reproduce. So it doesn't happen every time the Service saves the request object?

coolbest wrote:
The log4net worked for a while, but then it just died. Another mystery i just cannot get my head around.


I think it would be important to get this working. Does logging work for either piece (web / service). I don't have any experience with web apps, but I could help with the service, I have many win services in product that use log4net.

coolbest wrote:
In regards to the versions - i'm not sure. Not explicitly, unless NHibernate does that quitly in the background for me.


NHib does not do it for you. In your mapping file, you would specify the version. For instance, in my mapping file, I use:

Code:
<version name="NhVersion" column="nh_version" type="long" unsaved-value="null" />


With this, NHibernate knows whether it has the latest version of an object or if some other application / process has updated the data and it is stale.

So, if two users try to update the same object, the second user will get a "StaleObjectStateException". (Well, I catch the exception and display a friendly message, but you get the idea).

So, my suggestions would be to add a version property to each of your business objects, since you have concurrency issues. And I would try to tackle the issue with log4net so we can see exactly what is happening.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.