Register  |  Login



Question

Status: Closed Points: 200 Time: 15:23 - Aug 01, 2006  

Anpanman

NHibernate deadlock problem

I am developing a website using the O/R mapper NHibernate, and sometimes i get this error:

System.Data.SqlClient.SqlException: Transaction (Process ID xxx) was deadlocked on lock resources with another process and has been chosen as the deadlock victim

I was using NHibernate transactions, but have tried to disable that in order to see if the problem would persist and it's still there. Is NHibernate internally using transactions even when only retrieving data?
How can or should I handle this practically and in terms of application architecture?

Answer Discussion
Answer Summaries

 

Q&A System for Websites and Corporate Collaboration

Advertisement

  • Generates significant organic traffic for websites
  • Saves companies money, resources, and time

Anpanman

Date:: Aug 08, 2006

Time:: 16:56

I think I might have found a way to solve the problem.
The issue was that I had some batch operations running every x hours updating some data and it seems that those were causing reads on the same data to be deadlocked.
So now I'm trying to let dirty reads be possible, when I'm doing those updates:

ITransaction tr = session.BeginTransaction(IsolationLevel.ReadUncommitted);

Any save is done within a transaction like this.
The problem is that it's difficult to test thoroughly, since the problems was only ocurring once in a while.
I'll post here again about the result.

Anpanman

Date:: Aug 25, 2006

Time:: 01:40

After testing for a few weeks without getting any problems, I regard the problem as solved.

Anpanman

Date:: May 04, 2007

Time:: 17:39

I discovered another issue that might create deadlock problems. It's not related directly to transactions, but to nhibernates handling of dirty objects.
Basically what happened was that i selected a bunch of objects, and looking at the sql trace i saw that they were all immediately updated to the database again. What happens is that if nhibernate detects a "dirty" object, i.e. it has a property that has changed value, it will try to save it to the database per default.
I had a property that i tried to define with my own enum class although it was an integer that was finally saved in the database. well, nhibernate saw that as dirty since the int was not equal to the enum type and therefore saved the object again. this made a huge amount of saves and caused deadlocks simply because the database was overloaded with updates to the same tables and registries.
hope this helps somebody...

Question Answered

This question has been closed, and points have been rewarded to the following experts:

Anpanman: 200

You're welcome however to comment or give additional information or if you wish, you have the ability to write an Answer Summary for the Summary Area.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

No summaries have been submitted yet. Want to be the first?

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Websites Experts

View More

Rank

Expert

Points

1.

LAGM

900

2.

rcastagna

500

3.

oracleofDelphi

355

4.

nidhi

335

5.

PeterNZ

280

6.

multani.sarbjit

200

7.

jgivoni

190

8.

barun

75

9.

dustPuppy

75

10.

john2

65

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es