-->
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.  [ 2 posts ] 
Author Message
 Post subject: Pessimistic Locking
PostPosted: Wed Sep 29, 2004 8:39 am 
Newbie

Joined: Sun Sep 26, 2004 11:36 am
Posts: 7
Hi All,

If I want to solve my concurrency problems where I want one operation to finish before the other one can proceed is it "safe" todo something like this (regarding locking the object). Pretending I was using it wisely, when is the lock released ?


public void saveUser(User user) throws DAOException
{
Session session = null;

Transaction tx = null;

try
{
session = sessionFactory.openSession();

tx = session.beginTransaction();

session.lock(user,LockMode.WRITE);
etc


public void dleteUser(User user) throws DAOException
{
Session session = null;

Transaction tx = null;

try
{
session = sessionFactory.openSession();

tx = session.beginTransaction();

session.lock(user,LockMode.WRITE);

etc

/Tom


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 10:57 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
The lock should be released after tx.commit() or tx.rollback();

_________________
Leonid Shlyapnikov


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