-->
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.  [ 6 posts ] 
Author Message
 Post subject: pessimistic locking across several transactions
PostPosted: Fri Jul 02, 2004 5:29 am 
Newbie

Joined: Fri Jul 02, 2004 5:20 am
Posts: 8
Location: Montpellier France
Hi Everybody,

I'm working on a layered web application and I reached the save() step of a several request/response cycles.

During the 7 first steps the user is filling forms and the business layer perform business rules checking
upon those entries.

Just before saving all the data the user entered I need to verify at a business level that the data are still valid.
(I check their compatibility is still ok which involves several data access and tests in between)

To garantee these tests I would like to perform a pessimistic locking of several rows of several tables during the tests :

In the business object that save data, I plan to do something like :


lockRows(aideFinanciere);

boolean testIsOk =
check(aideFinanciere);// this method involves several
//hibernate queries and transactions

if testIsOk {
save(aideFinanciere);
unlockRows(aideFinanciere);
success=true;
} else {
success=false;
...

unlockRows(aideFinanciere);
}



aideFinanciere is not a persistent object. It is aggregating the data that the user is submiting across several requests.

The lock period of time is less than 1 second range but is necessary to make sure that I can trust the tests.

Is it possible to lock the rows and tables involved in the tests with a pessimistic lock transaction
that would keep unclosed across several other transactions?

Should I implement a "pessimistic offline lock" or is it possible to have an online lock?

Thanks in advance,
Eric Manuguerra

PS : My Hibernate version is 2.1
I'm working with ORACLE 8 database


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 6:01 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate will never lock in the application tier, so you don't have offline pessimistic locks. use LockMode (see docs) for database pessimistic locking. Do you know about versioning and optimistic locking?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 8:19 am 
Newbie

Joined: Fri Jul 02, 2004 5:20 am
Posts: 8
Location: Montpellier France
I've read the Hibernate online reference paragraph 10.4 about optimistic concurrency control.
I don't think it can be used in my case because some of the rows I want to lock
can be modified without making the tests coming to fail.
Which means the timeStamp version is not a reference in order to know if the data can be inserted.

I would like to get insurance on the tests and to lock the data that are involved in it.

What will happen if
- I make a select of those rows with an upgrade lockmode and keep this transaction open in a DAO
- perform the tests in the business tier (which means open and close new transactions and select the some of the same rows in the persistence layer)
- save the data,
- and then call the unlock method of the DAO to close the transaction

Will I have a conflict between the transactions that perform the test and the one that is locking the rows of the database?

Thank You Mr Bauer,

Eric Manuguerra


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 8:19 am 
Newbie

Joined: Fri Jul 02, 2004 5:20 am
Posts: 8
Location: Montpellier France
I've read the Hibernate online reference paragraph 10.4 about optimistic concurrency control.
I don't think it can be used in my case because some of the rows I want to lock
can be modified without making the tests coming to fail.
Which means the timeStamp version is not a reference in order to know if the data can be inserted.

I would like to get insurance on the tests and to lock the data that are involved in it.

What will happen if
- I make a select of those rows with an upgrade lockmode and keep this transaction open in a DAO
- perform the tests in the business tier (which means open and close new transactions and select the some of the same rows in the persistence layer)
- save the data,
- and then call the unlock method of the DAO to close the transaction

Will I have a conflict between the transactions that perform the test and the one that is locking the rows of the database?

Thank You Mr Bauer,

Eric Manuguerra


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 04, 2004 2:48 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Never use locks in web application, if you must use lock then do not use it too.
Try to find better way to solve the same problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 6:46 am 
Newbie

Joined: Fri Jul 02, 2004 5:20 am
Posts: 8
Location: Montpellier France
Thanks for your advice, anyway I'm going to lock for a very short period of time using the HibernateUtil class to pool a thredsafe session that will handle the lock.

_________________
----------------------
Eric Manuguerra


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