-->
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.  [ 4 posts ] 
Author Message
 Post subject: Waiting on a lock and @Entity
PostPosted: Wed Jun 29, 2011 11:58 am 
Newbie

Joined: Fri Jun 24, 2011 3:57 pm
Posts: 2
I am working on a project using Spring and Hibernate and Java 6.

We are using an MX/SQL relational database running on HP Nonstop. Client tests (and our tests) are showing occasional Error 73, meaning a database lock conflict. We believe that these conflicts are temporary, and that if the thread that hits this error waits and retries, instead of throwing an Exception right away, the conflict would soon not be a problem on the retry.

The ANSI SQL command-line appears to allow
SET LOCK WAIT <number of seconds>

However, the LockMode in hibernate seems to offer no equivalent to waiting on locks
http://docs.jboss.org/hibernate/core/3.5/javadoc/org/hibernate/LockMode.html
and LockOptions seems to only apply when one has a Query object or similar.

We use optimistic locking and annotations like
@Entity, @Table and @org.hibernate.annotations.GenericGenerator.

How is one supposed to wait on locks and retry using @Entity?
Or can we set this in the XML file at the DataSource or JDBCConnection level?

Thanks very much for your help.

Mary-Anne


Top
 Profile  
 
 Post subject: Re: Waiting on a lock and @Entity
PostPosted: Thu Jun 30, 2011 1:16 pm 
Newbie

Joined: Thu Apr 21, 2011 8:59 am
Posts: 14
Hi Mary-Anne,

It appears that the understanding of optimistic locking in hibernate is not very clear to you. You can go through this http://docs.jboss.org/hibernate/core/3.3/reference/en/html/transactions.html for a better understanding.

In short, optimistic locking is based on version number check of the entities being updated. And an OptimisticLockException will be thrown in case of conflicts. And it would the application's responsibility to retry the operation that has run into the exception. AFAIK, hibernate does not have any such support to do automatic retries in case of optimistic lock exception.

And if you are talking about waiting on locks, you can look at pessimistic locking where entities are explicitly locked before update. This causes other threads which are trying to update to wait for the lock.

Hope that helps.

_________________
Lokesh, C
( SCBCD 5, CCENT, SCJP 5 )


Top
 Profile  
 
 Post subject: Re: Waiting on a lock and @Entity
PostPosted: Fri Jul 01, 2011 4:07 am 
Newbie

Joined: Fri Jul 01, 2011 3:00 am
Posts: 1
Thanks you for the post.
Hi guys, Im a newbie. Nice to join this forum.

_________________
Watch Kung Fu Panda 2 Online Free


Top
 Profile  
 
 Post subject: Re: Waiting on a lock and @Entity
PostPosted: Tue Jul 19, 2011 7:22 pm 
Newbie

Joined: Fri Jun 24, 2011 3:57 pm
Posts: 2
Thanks for the URL. You're right. I do not understand this as well as I need to...yet.

I am exploring how to switch from optimistic locking to pessimistic locking.

I am using hibernate 3.3.2.

I create the session by defining an AnnotationSessionFactoryBean in the applicationContext.xml.

I declare persisted objects in the data model using annotations like
@Entity
@Table(name = "MYTABLE")
@org.hibernate.annotations.Entity(mutable = false)

I am having lock errors among multiple tables, so I would first like to try the equivalent of pessimistic locking for all of my data model, to see if performance is acceptable. In later versions of hibernate, it appears possible to set the lock mode on the session, but not in 3.3 as far as I can tell. Anyway, if there is a way to tell the SessionFactory in the ApplicationContext.xml to create sessions with a specific lock mode without creating a subclass of the Sessionfactory class, I have not found it yet. Does anyone know whether this way to do things is possible?

I have looked at setting the isolation level of my JDBC connection instead of messing with lock mode, since the javadoc recommends doing this, but I am not sure how lock modes and isolation levels map onto each other. Let's say I set the isolation level of my data source to SQL_TXN_SERIALIZABLE (which my MX/SQL database supports) using the ApplicationContext.xml. Is that the same as doing pessimistic locking for all data model objects?

I know if that's too slow I will have to lock only some of the data model classes.

Thanks in advance for any advice,

Mary-Anne


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