13 Filtering data


This chapter covers

  • Cascading state transitions
  • Listening to and intercepting events
  • Auditing and versioning with Hibernate Envers
  • Filtering data dynamically

In this chapter, we analyze many different strategies for filtering data as it passes through the Hibernate engine. When Hibernate loads data from the database, we can transparently restrict the data seen by the application with a filter. When Hibernate stores data in the database, we can listen to such an event and execute some secondary routines: for example, write an audit log or assign a tenant identifier to the record.

We explore the following data-filtering features and APIs:

13.1 Cascading state transitions

13.1.1 Available cascading options

13.1.2 Transitive detachment and merging

13.1.3 Cascading refresh

13.1.4 Cascading replication

13.2 Listening to and intercepting events

13.2.1 JPA event listeners and callbacks

13.2.2 Implementing Hibernate interceptors

13.2.3 The core event system

13.3 Auditing and versioning with Hibernate Envers

13.3.1 Enabling audit logging

13.3.2 Creating an audit trail

13.3.3 Finding revisions

13.3.4 Accessing historical data

13.4 Dynamic data filters

13.4.1 Defining dynamic filters

13.4.2 Applying the filter

13.4.3 Enabling the filter

13.4.4 Filtering collection access

13.5 Summary