Description
When using JPA with the 2nd-level cache enabled, it is required to invalidate cached items explicitly if the corresponding database records have been altered bypassing Hibernate (native queries, Criteria API bulk updates, patches directly in the DB itself etc.). Debezium can be used to achieve this task.
We should provide a blog post / demo and perhaps even an integration module for Hibernate ORM which shows how to do this task:
- Use the Debezium embedded engine to consume CDC events in the app that uses Hibernate
- Call JPA 2.0's Cache API to evict any updated/deleted items
The challenge is how to do it generically, i.e. we must be able to derive the entity key with the correct property type from the incoming change event. Another question is whether it'd be needed to avoid evictions caused by the application itself (in which case we'd somehow have to tell those apart from external updates).