Web hosting contract - CHAPTER 12 Modifying objects efficiently Regional data Often,
CHAPTER 12 Modifying objects efficiently Regional data Often, data is stored with a regional code (for example, all business contacts of a sales team). Each salesperson works only on a dataset that covers their region. Temporal data Many enterprise applications need to apply time-based views on data (for example, to see a dataset as it was last week). Hibernate s data filters can provide basic temporal restrictions that help you implement this kind of functionality. Another useful concept is the interception of Hibernate internals, to implement orthogonal concerns. 12.3.2 Intercepting Hibernate events Let s assume that you want to write an audit log of all object modifications. This audit log is kept in a database table that contains information about changes made to other data specifically, about the event that results in the change. For example, you may record information about creation and update events for auction Items. The information that is recorded usually includes the user, the date and time of the event, what type of event occurred, and the item that was changed. Audit logs are often handled using database triggers. On the other hand, it s sometimes better for the application to take responsibility, especially if portability between different databases is required. You need several elements to implement audit logging. First, you have to mark the persistent classes for which you want to enable audit logging. Next, you define what information should be logged, such as the user, date, time, and type of modification. Finally, you tie it all together with an org.hibernate.Interceptor that automatically creates the audit trail. Creating the marker interface First, create a marker interface, Auditable. You use this interface to mark all persistent classes that should be automatically audited: package auction.model; public interface Auditable { public Long getId(); } This interface requires that a persistent entity class exposes its identifier with a getter method; you need this property to log the audit trail. Enabling audit logging for a particular persistent class is then trivial. You add it to the class declaration for example, for Item:
In case you need quality webspace to host and run your web applications, try our personal web hosting services.