The most intelligent Java IDE
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Object Relational Mapping
 
RSS feed
 
New topic
Author

simulating select for update in hibernate.

Chase Bonham
Ranch Hand

Joined: Jul 15, 2006
Messages: 50

I have a POJO mapped to a table (one primary key) and everytime I do an update to a row of that table I want to do a "select for update" effectively locking
other people from concurrently making the update. Is there a hibernate 2.0
mapping attribute I can use?
Ghulam Rashid
Ranch Hand

Joined: Jan 14, 2002
Messages: 278

Probably you have use LockMode feature of Hibernate.


Transaction transaction = session.beginTransaction();
Country country =
(Country) session.get(Country.class, id, LockMode.UPGRADE);
cat.setName("India");
transaction.commit();

Country will be loaded into session using a SELECT FOR UPDATE,
thus locking the retrieved rows in the database until they�re released when the transaction ends.

Hope this will help.

Rashid
Ghulam Rashid
Ranch Hand

Joined: Jan 14, 2002
Messages: 278

correction to above code.
country.setName("India");
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Object Relational Mapping
 
RSS feed
 
New topic
The most intelligent Java IDE

.