...
If there's one thing you have to understand to successfully use JPA (Java Persistence API) it's the concept of a Cache. Almost everything boils down to the Cache at one point or another. Unfortunately the Cache is an internal thing and not exposed via the JPA API classes, so it not easy to touch or feel from a coding perspective.
Here's a quick cheat sheet of the JPA world:
- A Cache is a copy if of data, copy meaning pulled from but living outside the database.
- Flushing a Cache is the act of putting modified data back into the database.
- A PersistenceContext is essentially a Cache. It also tends to have it's own non-shared database connection.
- An EntityManager represents a PersistenceContext (and therefore a Cache)
- An EntityManagerFactory creates an EntityManager (and therefore a PersistenceContext/Cache)
...