Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Named query not reading from the database

 
Brendan Healey
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm using Eclipselink and run a named query, but was surprised to find that it's not reading the
data from the database. I really had always thought that it would do. For example I going into
the mysql command line application and change some data (&commit), but when the query
re-runs it's returning the old value. I tried the DoNotCheckCache query hint but this makes no
difference, only if I call EntityManager.refresh() on the object does it refresh the data.

Is this the expected behaviour? I'm a little surprised to be finding something like this out so
late in the day, I suppose I've not noticed before because changes normally occur from within
the persistence context.



Regards,
Brendan.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EclipseLink maintains a cache (2nd level) by default.

If you will have other applications modify your data you can disable the cache using,
<property name="eclipselink.cache.shared.default" value="false"/>

See,
http://wiki.eclipse.org/EclipseLink/FAQ/How_to_disable_the_shared_cache%3F



 
Brendan Healey
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, of course it does, it was the fact that I was changing the data from outside the persistence
context that was throwing me, this being a marginal scenario in a testing environment. I found some
cache information in the JPA 2 (Keith/Schincariol) which was missing from the index. They describe
the @Cacheable annotation and some EntityManagerFactory.getCache() methods. The persistence.
xml file can have a <shared-cache-mode> element and this is supported by NetBeans in the "design"
mode when editing persistence.xml.

The funny thing is that I do occasionally change other db fields from outside the JPA application and
they do seem to get picked up, what's probably happening I'm re-deploying causing the cache to be
invalidated.

Thanks for your help.

Regards,
Brendan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic