Finally, we will discuss how the entity versioning feature of the sample application was
implemented using Hibernate's Envers module.
Database Backend
For database backend, the JDBC embedded database with H2 will be used. However, the scripts
(database creation script, initial data population script) will be designed to be compatible with MySQL
too. So, when desired, the application is able to use MySQL as the backend database.
For Spring's ApplicationContext configuration, we will simply use the <jdbc:embedded-database>
tag to declare an embedded database. Two SQL scripts will be developed. One (called schema.sql) is for
database creation, and the other (called initial-data.sql) is for initial data population (e.g., initial
users, categories and subcategories, sample blog entries, etc.).
Using JPA for Persistence Layer Implementation
As mentioned in Chapter 3, for the persistence layer, two different implementations will be provided.
One will use JPA, while the other will use MyBatis.
For the JPA implementation, we will use JPA 2, with Hibernate as the persistence provider. All the
entity classes will be placed under the package com.apress.prospring3.springblog.domain, and the
object-to-relational mapping properties will be defined by using standard JPA 2 annotations (under the
javax.persistence package).
In addition, we will use Spring Data JPA to simplify the various database operations. All the
repository interfaces (e.g., the EntryRepository interface for supporting the Entry entity class) will be
placed under the package com.apress.prospring3.springblog.repository. Moreover, in order to support
browsing blog entries in the web application frontend, pagination support will be implemented.
In terms of database operations, querying is the most complicated part. In the frontend, users can
choose to filter entries by posting dates, categories, and subcategories, and so on. To fulfill this
requirement, we will use JPA 2's strongly typed criteria query API.
Auditing and Entity Versioning
In the sample application, all blog entries and comments will have auditing features enabled.
With the help of Spring Data JPA's auditing feature, we will keep track of basic audit information
(created by, created date, last modified by, last modified date) for blog posting and comments.
When a blog posting entry or comment is updated, Hibernate's Envers module will be used for
keeping versions of each record. History tables will be created for blog posting and comment tables to
keep the history records.
For details, please refer to Chapter 21.
Summary
In this chapter, we covered the basic concepts of JPA and how to configure JPA's EntityManagerFactory
in Spring, using Hibernate as the persistence service provider.
Then, we discussed using JPA to perform basic database operations. Advanced topics included
native queries and the strongly typed JPA criteria API.
Then we demonstrated how Spring Data JPA's Repository abstraction can help simplify JPA
application development, as well as how to use its entity listener to keep track of basic auditing
information for entity classes. For full versioning of entity classes, using Hibernate Envers to fulfill the
requirement was also covered.
In the next chapter, we will discuss another popular data access library: MyBatis (formerly known
as iBATIS).
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home