File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes LockMode.UPGRADE produces false sql ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "LockMode.UPGRADE produces false sql ?" Watch "LockMode.UPGRADE produces false sql ?" New topic
Author

LockMode.UPGRADE produces false sql ?

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I want to lock a record via JPA/Hibernate.

I use the actual version of Hibernate and actual DB2-Database.

I will lock a record of type User:



The Hibernate-API says:




but I cannot find any "select..for update"-clause in this sql which was generated after declaring LockMode.UPGRADE:



Why does Hibernate not produce this:




What is false? (My Database DB2 uses Cursor Stability (CS)), but hibernate overwrite this with ISOLATION(RS).


Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

"Select ... for update" is Oracle syntax. Does DB2 support it?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
hello,

yes, DB2 supports it:

http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/db2/rbafzmstintsel.htm (look for "update-clause")
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Looks like a bug.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
what a pitty,

issue created at 20/Feb/06.. a FOUR Years old bug for such a common thing?!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I dunno - pessimistic locking and DB2 doesn't sound like that common a mixture to me. But annoying if you need it, I agreee!

You could always revert to a SQL query.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
however, thanks.


pessimistic locking and DB2 doesn't sound like that common a mixture to me


why?

I only want to lock records for update, so that other processes are not able do an update while I am working with that records.
I am working with that records and after the work is done, I will update it (and then it will be unlocked) - is that not common?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

It is in my experience. 14 years a developer writing a whole range of applications in a wide range of technologies (all database backed) and I've only once had to use pessimistic locking. And as for DB2 - outside its mainframe market (which is a whole different beast) - its market share is pretty small I understand.

The reason people tend not to use pessimistic locking is because it introduces a bottleneck into their application and it usually takes a really compelling reason to introduce a bottleneck.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LockMode.UPGRADE produces false sql ?
 
Similar Threads
locking table to get the new session id
pagination via ScrollableResults or via setFirstResult
tuple in jql/hql
Optimistic & Pesimistic locking
PreparedStatement error shown