Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Thread safety</h3> <p>I have a doubt about the way you manage your <code>EntityManager</code>. While a <code>EntityManagerFactory</code> is thread-safe (and should be created once at the application startup), an <code>EntityManager</code> is not and you should typically use one <code>EntityManager</code> per thread (or synchronize accesses to it but I would use one per thread).</p> <h3>Concurrency</h3> <p>JPA 1.0 supports (only) optimistic locking (if you use a <code>Version</code> attribute) and two lock modes allowing to avoid <em>dirty read</em> and <em>non repeatable read</em> through the <a href="http://docs.oracle.com/javaee/5/api/javax/persistence/EntityManager.html#lock%28java.lang.Object,%20javax.persistence.LockModeType%29" rel="nofollow noreferrer"><code>EntityManager.lock()</code></a> API. I recommend to read <a href="http://en.wikibooks.org/wiki/Java_Persistence/Locking#Read_and_Write_Locking" rel="nofollow noreferrer">Read and Write Locking</a> and/or the whole section <strong>3.4 Optimistic Locking and Concurrency</strong> of the JPA 1.0 spec for full details. </p> <p>PS: Note that <a href="http://en.wikibooks.org/wiki/Java_Persistence/Locking#Pessimistic_Locking" rel="nofollow noreferrer">Pessimistic locking</a> is not supported in JPA 1.0 or only through provider specific extensions (it has been added to JPA 2.0, as well as other locking options). Just in case, Toplink supports it through the <code>eclipselink.pessimistic-lock</code> query hint.</p> <hr> <p>As written in the JPA wiki, TopLink Essentials is supposed to support pessimistic locking in JPA 1.0 via a query hint:</p> <pre><code>// eclipselink.pessimistic-lock Query Query = em.createQuery("select f from Foo f where f.bar=:bar"); query.setParameter("bar", "foobar"); query.setHint("eclipselink.pessimistic-lock", "Lock"); query.getResultList(); </code></pre> <p>I don't use TopLink so I can't confirm this hint is supported in all versions. If it isn't, then you'll have to use a native SQL query if you want to generate a "FOR UPDATE".</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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