aspose file tools*
The moose likes Object Relational Mapping and the fly likes simulating select for update in hibernate. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "simulating select for update in hibernate." Watch "simulating select for update in hibernate." New topic
Author

simulating select for update in hibernate.

Chase Bonham
Ranch Hand

Joined: Jul 15, 2006
Posts: 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
Posts: 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
Posts: 278
correction to above code.
country.setName("India");
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simulating select for update in hibernate.