• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA/Hibernate Query Returns Stale Results

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 call.

In another JVM, I query for the DummyObject doing a call like the following



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.

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? Is there something I can set through query.setHint( , )?

Maybe I don't understand "EXTENDED" vs TRANSACTIONAL correctly.
 
Ranch Hand
Posts: 69
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The query will not see the latest data till you do not commit the data from the extended persistent context.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic