Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: Is there a risk for deadlocks when using locking?

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've heard when using locking in Hibernate that the risk for deadlocks rise.

Is that true
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by locking? Are you talking about pessimistic locks? Or optimistic locks (versioning as its know in Hibernate). Do you have a source for your claim?

One thing I can say, ignoring Hibernate, whether or not deadlocks are likely in a relational database is more down to what transaction isolation level you use and which database you use.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The claim comes from a friend of mine, so I can not give you any link to that claim. I'm new to that issue and just started to read chapter 10 and 11 from the book Java Persistence with Hibernate.

We have some consistency problems with our database, and recognized that we haven't enabled any kind of locking. Regarding the quotation below I think we can (and should) only use optimistic locking.

from p. 625 Java Persistence with Hibernate
Currently, pessimistic locking isn�t available (but it�s
planned as a Hibernate extension hint)


I am also not sure whether we can make such a general statement as my question suppose .
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'd ask you friend to explain.

Pessimistic locking is an unusual choice in database backed applications. It creates a single threaded bottleneck in a system that is usually meant to easily handle concurrency. There will be the odd instance where you will need such behaviour, but this is the exception not the rule.

Optimistic locking is a common way to avoid loosing updates. I'd implement it as standard in a database backed application.
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
Pessimistic locking is an unusual choice in database backed applications. It creates a single threaded bottleneck in a system that is usually meant to easily handle concurrency. There will be the odd instance where you will need such behaviour, but this is the exception not the rule.


In an enterprise application I don't see where this kind of locking (bottleneck with serialized transactions) at all has its usage.

Originally posted by Paul Sturrock:
Optimistic locking is a common way to avoid loosing updates. I'd implement it as standard in a database backed application.


This seems also to be the way for handling (enterprise) applications where scalability and concurrency is most important. Beside what I've heard about the deadlock I would like to hear your opinions on that issue.

As soon as I get more information on it, I'll post them here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic