I use the EXTENDED persistent context because it will allow me to lazily load the relations of one object on an object, and it will not require SELECT before merging an object with a constant context.
I have a DummyObject with:
This object is updated every 5 seconds in one JVM with a call em.merge(DummyObject).
In another JVM, I request for a DummyObject making a call as shown below
em.createQuery("from DummyObject").getResultList();
I also execute this request every 5 seconds.
The problem is that the objects resulting from the query have a timestamp for the very first query after successive calls, although Hibernate generates the correct SQL statement (when I turn on logging) and the database receives updates correctly (I checked).
I also tried all kinds of optimistic locks using @Version to no avail. (See Comments)
Another thing is that it works correctly when:
I change PersistentContextType to TRANSACTIONAL (something that won't let me lazily load ONE-MANY)
I call the EntityManager.clear () call before I make the request above (Something that also won't allow me to lazily load ONE MANY relationships).
? .
- ? -, query.setHint(,)?
, < EXTENDED " TRANSACTIONAL.