Chapter 18. Testing JPA-based applications

 

Unfortunately we need to deal with the object relational (O/R) impedance mismatch, and to do so you need to understand two things: the process of mapping objects to relational databases and how to implement those mappings.

Scott W. Amber, Mapping Objects to Relational Databases: O/R Mapping In Detail

This chapter covers

  • Multilayered application testing
  • Using DbUnit to test JPA applications
  • JPA mapping tests
  • Testing JPA-based DAOs
  • Verifying JPA-generated schema

Most Java applications need to store data in persistent storage, and typically this storage is a relational database. There are many approaches to persisting the data, from executing low-level SQL statements directly to more sophisticated modules that delegate the task to third-party tools.

Although discussing the different approaches is almost a religious matter, we assume it’s a good practice to abstract data persistence to specialized classes, such as DAOs. The DAOs themselves can be implemented in many different ways:

  • Writing brute-force SQL statements (such as the UserDaoJdbcImpl example in chapter 17)
  • Using third-party tools (like Apache iBATIS or Spring JDBC templates) that facilitate JDBC programming
  • Delegating the whole database access to tools that map objects to SQL (and vice-versa)

18.1. Testing multilayered applications

18.2. Aspects of JPA testing

18.3. Preparing the infrastructure

18.4. Testing JPA entities mapping

18.5. Testing JPA-based DAOs

18.6. Testing foreign key names

18.7. Summary