Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I check if the db is locking between transactions
    text
    copied!<p>I am using Hibernate to implement the DAO layer <strong>(Sybase DB)</strong> in a web application running on <strong>Jboss5</strong>.</p> <p>The problem I am facing is when the client/UI makes multiple simultaneous HTTP calls - which in-turn calls the DAO insert method - there is a race condition which causes both calls to run the DAO insert method at near same time. What I actually want is </p> <blockquote> <ol> <li>The 1st request calls the DAO method</li> <li>1st request reads the current db value</li> <li>Check if new data is valid based on current db value</li> <li>If valid, insert the new value</li> <li>AND then the 2nd request to read the current db value</li> <li>Check if new data is valid </li> <li>If valid, insert the value...and so on if there are more calls</li> </ol> </blockquote> <p>My DAO layer code looks like so:</p> <pre><code>@Override @Transactional public Set&lt;PartyData&gt; insertPartyData(final Set&lt;PartyData&gt; pData) throws DataServiceException { sessionFactory.getCurrentSession().getTransaction().begin(); //code to read the current db value //validation code to check if new value can be inserted based on what's currently in db sessionFactory.getCurrentSession().save(pData); sessionFactory.getCurrentSession().getTransaction().commit(); } </code></pre> <p><strong>Question?</strong></p> <p>How can I make sure that the db locks the table for the duration of one transaction so that any other request waits until the previous transaction is complete?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload