Hibernate entity replication without database access in EAP 6
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 6
- Hibernate 4
Issue
- Specific Hibernate entities will not be written to (or loaded from) the database
- These entities will be created and updated in-memory only
- Replication of the state of these entities across clustered level two caches is desired
Resolution
Alternative solutions for in-memory caching include:
- Generic cache/replication (non-JPA interface) provided by Red Hat JBoss Data Grid (JDG)
- Hibernate/JPA caching without a backing database is possible with Hibernate OGM 1
- OGM may be used with Infinispan as the backing "NoSQL store"
- Infinispan based JDG might be leveraged for replication
-
This is an unsupported solution ↩
Root Cause
Hibernate and JPA are meant to be used with entities persisted to the database
- Insertion of entities into the level two cache (and replication to clustered caches) occurs when in-memory changes are committed for entities that participate in a Hibernate session
- Entities may only be inserted into a Hibernate session by using query methods or write methods such as
persist(...)ormerge(...)and these methods entail database reads or writes
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
