0

Situation:

  • App A (war running on a tomcat 7, rest interface for a web app)
  • App B (java standalone, scheduled batch jobs loading data from a file into a database)
  • In between a shared control table with a record per file.
  • App A correctly persists new record in the control table and sets appropriate state (pending), signalling App B to start processing.
  • Web app correctly displays the state as pending.
  • App B processes that batch, loads the data and correctly sets new state (processed) signalling the load has been completed. This is easily verified by simple query with fx Squirrel.
  • When refreshing the page in the web app the state is incorrectly displayed as pending instead of the correct state: processed. When debugging the response, the state variable is assigned pending. My logs indicate the query taking place on the refresh.
  • If I reboot my Tomcat the next query will show the correct result, i.e the state as processed. This also puzzles me, what besides EntityManager is maintaining the database object??

Problem: I just cannot figure out why App A continues to see the state as pending. I've already tried a number of things to ensure that the entityManager has it's cache cleared (both for App A and App B) but still App A queries end up getting the wrong state.

MMA
  • 13
  • 3
  • Are you flushing your EntityManager and refreshing you entities every time you update/insert both App A/App B? – Matteo Baldi Apr 04 '16 at 13:22
  • Commit on the transaction should flush. And of cause all my inserts/updates run in transactions and the true :-) state is easily verified with fx Squirrel. – MMA Apr 04 '16 at 13:24

2 Answers2

0

@Baldurian Thanks the hint. I added a refresh on the fetched object and it worked. I get my state via a child object. Turns out that the child object never was refreshed even though App A emptied the cache before every query. Not exactly the behaviour I was expecting.

MMA
  • 13
  • 3
0

EclipseLink by default maintains a second level cache, which is outside the EntityManager and why clearing the EntityManager cache doesn't help.

You can refresh as mentioned above, but this requires knowledge of when changes are made so that you know when a refresh is required - and care needs to be taken as refresh wipes out changes.

If you are going frequently make changes outside of this JPA application, it might be better to disable the shared cache on some or all Entities. The <property name="eclipselink.cache.shared.default" value="false"/> property can be used to disable it for all entities, or you can selectively pick and choose using the @Cache annotation

Chris
  • 20,138
  • 2
  • 29
  • 43