aspose file tools*
The moose likes Object Relational Mapping and the fly likes Row level lock in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Row level lock in Hibernate" Watch "Row level lock in Hibernate" New topic
Author

Row level lock in Hibernate

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10290
    
168

Is there any way by which we can configure Row level locking of tables while using Hibernate. Currently, in our application, Hibernate generates table level lock queries. Our's is a J2EE application on Jboss-3.2.3 and Hibernate 2.1.3?

Thank you.


[My Blog] [JavaRanch Journal]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Hibernate doesn't lock tables. All concurrent access issues are delegated to the RDBMS. How are you getting Hibernate to lock tables?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10290
    
168

I have NOT mentioned explicitly any locking configurations in Hibernate. But whenever queries are fired through Hibernate i see logs similar to the one below:



[Edited code to improve formatting - Paul Sturrock]
[ December 14, 2005: Message edited by: Paul Sturrock ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10290
    
168

Is there any way this can be avoided?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Hmm. Can you post the code that generates this SQL? Also which Dialect are you using?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10290
    
168

We are using Teradata dialect :



As far as the code is concerned, we have created a hibernate object which is mapped to this SM_TABLE_RUN. Then we just invoke the get method on our persistence manager which invokes Hibernate session.get method.
This behavior is observed for all sort of database operations (insert,update,delete etc...) and not just select operation.

P.S.: Hibernate is being used as a MBean in our application
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10290
    
168

Even a HQL like:


is issuing the following lock statements:

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Teradata? That is not a supported database as far as I'm aware. You might want to speak to whoever wrote your Dialect, they will probably have more of a clue (since it wasn't the Hibernate developers). Also, doesn't Teradata use a serializable transaction isolation level by default?
[ December 14, 2005: Message edited by: Paul Sturrock ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10290
    
168

Thanks Paul, Will try to get in touch with the guy who coded the dialect.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10290
    
168

Originally posted by Paul Sturrock:

Also, doesn't Teradata use a serializable transaction isolation level by default?

I have been informed that Teradata does NOT use a serializable transaction isolation level
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Hmm again. Are you explicitly applying a LockMode to the Session when you open it? I understood that it is posisble to add pessimistic locking to a row with this, but I've never heard of it locking a table.
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Calling LOCKING TABLE XXX FOR ACCESS is telling Teradata that dirty or phantom reads (TRANSACTION_READ_UNCOMMITTED) are acceptable.

This is a good thing [for concurrency].

You are declaring that others can access and update the table while you are selecting from it.

The valid lock levels are Exclusive, Write, Read and Access.
[ December 14, 2005: Message edited by: Scott Johnson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Row level lock in Hibernate