Prev Next

Hibernate / EclipseLink Interview questions

How do you troubleshoot stale data issues caused by EclipseLink's shared cache?

Stale-cache symptoms usually show up as a query returning an entity's old values even though the underlying row was clearly updated, most often traced to either a cluster where cache coordination isn't configured, or a database write that bypassed EclipseLink entirely.

  1. Check for out-of-band writes - a direct SQL update, a batch job, or a different application writing to the same table won't be reflected in EclipseLink's cache, since the cache only updates in response to changes it commits itself.
  2. Check cache coordination in clustered deployments - if the application runs on multiple JVM nodes without cache coordination (RMI/JMS) configured, a commit on one node has no way to invalidate the cached copy sitting on another node.
  3. Use the eclipselink.refresh hint for known-volatile queries - forces EclipseLink to bypass the cache and re-read from the database for that specific query, useful for data that's occasionally updated externally.
  4. Explicitly evict stale entries when needed - em.getEntityManagerFactory().getCache().evict(Entity.class, id) removes a specific cached entry on demand, useful right after a known out-of-band change.
  5. Reconsider whether the entity should be cached at all - for tables frequently modified outside EclipseLink's control, disabling caching for that entity type with @Cache(isolation = CacheIsolationType.ISOLATED) or a very short expiry may be more reliable than trying to keep the cache in sync.

The underlying principle is that EclipseLink's shared cache only knows about changes made through EclipseLink itself (or coordinated from another EclipseLink node); any write path outside that boundary needs an explicit refresh, eviction, or a conscious decision to exclude that data from caching altogether.

A common cause of stale shared-cache data is:
The eclipselink.refresh query hint is used to:

More Related questions...

What is EclipseLink? What is JPA (Jakarta Persistence API)? What is the relationship between EclipseLink and Jakarta Persistence? What is a Persistence Unit in EclipseLink? What is persistence.xml used for? What is an EntityManager in EclipseLink? What is an EntityManagerFactory? What is a JPA entity? What are EclipseLink's core components? What is EclipseLink MOXy? What is class weaving in EclipseLink? What is the EclipseLink shared cache (L2 cache)? What is a fetch group in EclipseLink? What is optimistic locking in EclipseLink and JPA? What is the @Convert annotation used for? What is a Customizer in EclipseLink? What is JPQL? What are EclipseLink query hints? What is DDL generation in EclipseLink? What is a UnitOfWork in EclipseLink's native API? What is EclipseLink's native Session API? What is static weaving in EclipseLink? What are EclipseLink descriptors? What is EclipseLink DBWS? What is EclipseLink SDO? Explain the lifecycle of a JPA entity managed by EclipseLink? Why is class weaving important for lazy loading in EclipseLink? How does EclipseLink's shared cache differ from Hibernate's second-level cache? What is the difference between static weaving and dynamic weaving? How do you configure batch fetching using EclipseLink query hints? When should you use pessimistic locking instead of optimistic locking? How do you troubleshoot lazy loading failures caused by missing weaving in EclipseLink? What is the difference between EAGER and LAZY fetch strategies, and how does EclipseLink implement lazy loading without a live session? How does EclipseLink implement change tracking for detecting entity modifications? Explain the internal working of EclipseLink's cache coordination? What is the difference between EclipseLink and Hibernate? How do you implement multitenancy in EclipseLink? Why use fetch groups instead of always fetching the full entity? What is the difference between attribute change tracking and deferred change detection? How does EclipseLink cache query results, and what invalidation strategies are available? When would you choose isolated cache over shared cache for a multitenant entity? How do you configure a Customizer to add native EclipseLink mappings not expressible via annotations? What is the difference between JPQL and the EclipseLink native Expression/Criteria API? Explain the internal working of EclipseLink's Unit of Work commit process? How do you optimize EclipseLink performance for a high-throughput application? What is the difference between EclipseLink's @Convert and JPA's standard AttributeConverter? How does EclipseLink decide when to use join fetch versus batch fetch? Why should you use @Version for optimistic locking instead of manual version checks? What is the difference between EntityManager persistence context types: transaction-scoped vs extended? How do you troubleshoot stale data issues caused by EclipseLink's shared cache?
Show more question and Answers...


Comments & Discussions