Thursday, November 29, 2007

Beyond the JPA and the possible cache problems

Yesterday I detect an strange behavior in a little JEE5 application: queried JPA data doesn't reflect the real state of the data when I was made changes on database through an external database client program.
Looking at google I found this very interesting post:
Understanding the cache of TopLink Essentials(GlassFish JPA)

Summarizing, the persistence provider, in this case TopLink maintains data in a session cache, maintaining it synchronized only if is modified through an EntityManager and it doesn't if you modify through an external tool. To avoid use the cache, with all its implication, you need to specify it explicitly.