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: Lock mode to wait. Hibernate
PostPosted: Wed Jan 25, 2012 6:21 am 
Newbie

Joined: Wed Jan 25, 2012 5:35 am
Posts: 3
Hi,

I'm using Spring+Hibernate in my application. The database used is Informix.
I'm testing concurrency and I want my application to wait for a while when
a query try to access a row that is locked. This time can be set in informix
whith 'SET LOCK MODE TO WAIT'. But I'm looking for a method in hibernate
or spring to do the same.

I tried setting a timeout in the transaction, but it did not work.

...
@Transactional(readOnly = false, propagation=Propagation.REQUIRES_NEW, isolation=Isolation.READ_COMMITTED, timeout=20)
...
getHibernateTemplate().getSessionFactory().getCurrentSession().getTransaction().setTimeout(11);
...

Could anyone help me?
Thanks.


Top
 Profile  
 
 Post subject: Re: Lock mode to wait. Hibernate
PostPosted: Tue Jan 31, 2012 4:21 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi,

one of the simplest ways to do this is, doing it through your connection pool configuration.
Most connection pool implementation allow to define SQL-statements which have to be executed before a
connection get borrowed to hibernate.
For example if you are using C3PO you can define:

<property name="hibernate.c3p0.testConnectionOnCheckout" value="true"/>
<property name="hibernate.c3p0.preferredTestQuery" value="SET LOCK MODE TO WAIT;select * from systables;"/>

N.B.: On C3PO the validation query must return at least one result (on other connection pool it may be enough, that it dont raises an exception)
As "SET LOCK MODE TO WAIT" probably does not return anything,
you probably have to define a second query like 'select * from systables;' or any query which without effort is returning a result.

Which connection pool are you using?
You could also check if your Informix JDBC-driver provides an apposite parameter in the connection url.


Top
 Profile  
 
 Post subject: Re: Lock mode to wait. Hibernate
PostPosted: Tue Jan 31, 2012 5:00 am 
Newbie

Joined: Wed Jan 25, 2012 5:35 am
Posts: 3
Hi, "pb00067"

Thanks a lot for your response,
I'm using a connection pool defined in Weblogic. I can set the 'lock mode to wait'
when I get the conection in Weblogic as an initial query. The problem is the next: there are some querys
which I want to wait more time for them than others. So, for this case I need to set the 'lock mode to wait' at the
level of the query. I could do this using a native query and setting the "lock mode to wait" before
executing my concrete query, and then when the query finishes I can set the "lock mode to wait" to it's default
value. But I would prefer not to use native querys, do you know any other solution?

Thanks in advance.

pb00067 wrote:
Hi,

one of the simplest ways to do this is, doing it through your connection pool configuration.
Most connection pool implementation allow to define SQL-statements which have to be executed before a
connection get borrowed to hibernate.
For example if you are using C3PO you can define:

<property name="hibernate.c3p0.testConnectionOnCheckout" value="true"/>
<property name="hibernate.c3p0.preferredTestQuery" value="SET LOCK MODE TO WAIT;select * from systables;"/>

N.B.: On C3PO the validation query must return at least one result (on other connection pool it may be enough, that it dont raises an exception)
As "SET LOCK MODE TO WAIT" probably does not return anything,
you probably have to define a second query like 'select * from systables;' or any query which without effort is returning a result.

Which connection pool are you using?
You could also check if your Informix JDBC-driver provides an apposite parameter in the connection url.


Top
 Profile  
 
 Post subject: Re: Lock mode to wait. Hibernate
PostPosted: Tue Jan 31, 2012 8:53 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
As with Informix it is not possible to specify the wait timeout within the select-statement itself,
I see not other way than toggling the wait-timeouts by using native querys.


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.