System.out.println("");
oldContact = contactService.findAuditByRevision(1l, 2);
System.out.println("");
System.out.println("Old Contact with id 1 and rev 2:" + oldContact);
System.out.println("");
}
}
From Listing 10-52, we first create a new contact and then update it. Then we retrieve the
ContactAudit entities with revisions 1 and 2, respectively. Running the code will produce the following
output:
Listing contacts without details:
Contact - Id: 1, First name: Tom, Last name: Jackson, Birthday: 2011-10-21, Create by:
prospring3, Create date: 2011-10-21T13:54:24.242+08:00, Modified by: prospring3, Modified
date: 2011-10-21T13:54:24.360+08:00
Old Contact with id 1 and rev 1:Contact - Id: 1, First name: Michael, Last name: Jackson,
Birthday: 2011-10-21, Create by: prospring3, Create date: 2011-10-21T13:54:24.242+08:00,
Modified by: prospring3, Modified date: 2011-10-21T13:54:24.242+08:00
Old Contact with id 1 and rev 2:Contact - Id: 1, First name: Tom, Last name: Jackson,
Birthday: 2011-10-21, Create by: prospring3, Create date: 2011-10-21T13:54:24.242+08:00,
Modified by: prospring3, Modified date: 2011-10-21T13:54:24.360+08:00
From the previous output, you can see that after the update operation, the ContactAudit's first name
was changed to Tom. However, when looking at the history, at revision 1, the first name is Michael. At
revision 2, the first name becomes Tom. Also notice that the last modified date of revision 2 reflects the
updated date-time correctly.
Considerations When Using JPA
Although this chapter is long, it covered only a small portion of JPA. For example, using JPA to call
database stored procedures was not covered. JPA is a complete and powerful ORM data access standard,
and with the help of third-party libraries like Spring Data JPA and Hibernate Envers, you can implement
various cross-cutting concerns relatively easily.
JPA is a JEE standard that is supported by most major open source communities as well as
commercial vendors (e.g., JBoss, GlassFish, WebSphere, WebLogic, and so on). So, it's a compelling
choice for adopting JPA as the data access standard. If you require absolute control over the query, you
can use JPA's native query support, instead of using JDBC directly.
In conclusion, for developing JEE applications with Spring, we recommend using JPA to implement
the data access layer. When desired, you can still mix in JDBC for some special data access needs. Always
remember that Spring allows you to mix and match different data access technologies easily with the
transaction management transparently handled for you.
Using JPA in the Sample Application
In this section, we will discuss the relationships between the topics discussed in this chapter and the
sample application that we will develop. Topics include the backend database and the JPA
implementation for various database operations.
We will also highlight how we adopt the features in Spring Data JPA to help simplify the data access
logic and keep track of the basic audit information.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home