I am using an
EXTENDED 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.
I have an DummyObject with:
1. A "Last Updated" Date Field
2. A One-Many Relationship
This Object is being updated every
5 seconds in one JVM through a
Code:
em.merge(DummyObject)
call.
In another JVM, I query for the DummyObject doing a call like the following
Code:
em.createQuery("from DummyObject").getResultList();
I am also doing this Query every
5 seconds.
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).
I have also tried all sorts of optimistic locking with @Version to no avail. (See comments)
Another thing is that this does work correctly when:
1. I change the PersistentContextType to
TRANSACTIONAL (something that will not allow me to lazily load the ONE-MANY relationship)
2. 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.
Why does my Query return stale data? I have no Second Level Caching or Query Caching enabled.
Am I doing something wrong? Maybe I don't understand "
EXTENDED" correctly.