Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA/Hibernate Query Returns Stale Results
    text
    copied!<p>I am using an <strong>EXTENDED</strong> Persistent Context because it will allow me to Lazily Load a one-many relationship on an object and it also won't require a SELECT before I "merge" an object with the persistent context.</p> <p>I have an DummyObject with:</p> <ol> <li><p>A "Last Updated" Date Field</p></li> <li><p>A One-Many Relationship</p></li> </ol> <p>This Object is being updated every <strong>5</strong> seconds in one JVM through a <code>em.merge(DummyObject)</code> call.</p> <p>In another JVM, I query for the DummyObject doing a call like the following</p> <pre><code>em.createQuery("from DummyObject").getResultList(); </code></pre> <p>I am also doing this Query every <strong>5</strong> seconds.</p> <p>The problem is, is that the Objects resulted from the Query all have a Timestamp of the very first Query after successive calls, even though Hibernate is generating the correct SQL statement (when I have statement logging on), and the Database is getting the updates correctly (I have verified).</p> <p>I have also tried all sorts of optimistic locking with @Version to no avail. (See comments)</p> <p>Another thing is that this does work correctly when:</p> <ol> <li><p>I change the PersistentContextType to <strong>TRANSACTIONAL</strong> (something that will not allow me to lazily load the ONE-MANY relationship)</p></li> <li><p>I do an EntityManager.clear() call before I do the Query above (Something that will also not allow me to lazily load the ONE-MANY relationship).</p></li> </ol> <p>Why does my Query return stale data? I have <strong>no</strong> Second Level Caching or Query Caching enabled.</p> <p>Am I doing something wrong? Is there something I can set through query.setHint( , )?</p> <p>Maybe I don't understand "<strong>EXTENDED</strong>" vs <strong>TRANSACTIONAL</strong> correctly.</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