Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate two simultaneous transactions on different machines
    primarykey
    data
    text
    <p>I have an ordering platform on a remote webserver and a local production machine here at my office. Both webservers access the same remote MySQL (InnoDB) database.</p> <p>My Problem: The production takes several minutes in which 2-3 transactions are open. In this time I generate new invoice numbers and increment them. The most recent invoice number is saved in a Numbers-Table on the database.</p> <pre><code>public Long getNewInvoiceNumber() { Criteria crit = getSession().createCriteria(Numbers.class); Numbers n = ((Numbers)crit.uniqueResult()); Long newNumber = n.getInvoiceNumber() + 1L; n.setInvoiceNumber(newNumber); return newNumber; } </code></pre> <p>Now when someone is saving a new order during the production they are accessing the same Numbers-Table to generate another number (not the invoice). All the orders processed by the production are saved with the correct invoice numbers. However, the Numbers-Table isn't updated with the newest value and the invoice number remains the same as before the production.</p> <p>I understand that one of the transaction gets a "stale table" message. But what is the behavior of MySQL / Hibernate / Java? I'd like to get an exception from one of the transactions so I can rollback and don't have this dangerous database inconsistency.</p> <p><strong>EDIT :</strong> This is how the table <code>Numbers</code> looks like:</p> <pre><code>id | invoice_number | tag_number 0 | 16533 | 1055 </code></pre> <p><code>id</code> is the primary key. I only access this one row and increase the needed number.</p> <p><strong>EDIT 2 :</strong> Okey, I see that this table structure is kinda bad. I updated it to:</p> <pre><code>id | number invoice_number | 16533 tag_number | 1055 </code></pre> <p>Now I can access each row independently. Don't know if that solves my problem though.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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