Pro JPA 2 Mastering the Java Persistence API


Author(s): Mike Keith, Merrick Schincariol.
ISBN: 1430219564
Published: Dec 2009
Relevance: 5/5
Readability: 5/5
Overall: 5/5

More Apress Books Reviews …

In these days for an Enterprise for its application is mandatory has a mechanism of persistence and easy way to access them, JPA 2.0 is an important option to be consider, important part of the whole package of JEE 6.

Thus this book let you learn from the scratch JPA 2.0, with an easy curve, already experimented programmers could consider this book like a good reference, below the TOC

  • Chapter 01: Introduction
  • Chapter 02: Getting Started
  • Chapter 03: Enterprise Applications
  • Chapter 04: Object-Relational Mapping
  • Chapter 05: Collection Mapping
  • Chapter 06: Entity Manager
  • Chapter 07: Using Queries
  • Chapter 08: Query Language
  • Chapter 09: Criteria API
  • Chapter 10: Advanced Object-Relational Mapping
  • Chapter 11: Advanced Topics
  • Chapter 12: XML Mapping Files
  • Chapter 13: Packaging and Deployment
  • Chapter 14: Testing
  • Chapter 15: Migration

Chapter 01: Introduction

Starting quickly about ORM, covered with valuable theory and even including some interesting opinions. Then many important topics like:

  • Class Representation
  • Relationships
  • Inheritance

Each one covered with many alternatives available to accomplish each option, even including its respective explanation, really well done, therefore you know about how complex are these topics and how ORM resolve this

History for Java through its persitence support is covered, therefore JDBC, EJB, JDO are mentioned detailed, you know the pros and cons of each one. Therefore then EJB 3.0 and JPA 1.0 is introduced, later then JPA 2.0

Chapter 02: Getting Started

Starting quickly covering Entity Overview with concrete and valuable theory about important topics like: Persistability, Identity, Transactionality and Granularity. Then Entity Metadata is introduced and covering about XML and annotations.

With all this, a simple sample code working with a simple POJO and how it is transformed in an Entity is available. Then an important material is introduced, about the Entity Manager, even including an image showing all the JPA concepts, therefore you have a clear idea about how these components are related among them. Then the CRUD concept is applied to work with the Entity Manager, therefore, persisting, finding, removing and updating are covered, with a simple snippet code with its respective explanation. Even more Transactions and Queries are covered

With all this all these snippet code is shown together and Tested. Finally Persistence Unit is introduced to complete the sample code

Chapter 03: Enterprise Applications

Long chapter, mostly covered with a lot of theory and snippet code. Therefore important topics are covered like:

  • Sessions Beans (Stateless and Stateful, even including for each one its Lifecycle Callbacks)
  • Singleton Session Beans
  • Message-Driven Beans
  • Dependency Management
  • Transaction Management (Container-Managed and Bean-Managed)

Chapter 04: Object-Relational Mapping

Other long chapter, well covered, valuable theory and even important images are included many times for a better understanding, of course, snippet source code with its repective explanation is available, the most important topics are

  • Annotations (@Entity, @Id, @Table, @Column, @Basic, @Temporal)
  • Mapping the Primary Key (the four approaches are covered)
  • Relationships (roles, directionality,cardinality, ordinality)

The associations is well covered, all the different options like One-To-Many and others, for each one an image is available for a better understanding

Chapter 05: Collection Mapping

A complement of the last section mentioned for the previous chapter. Starting covering about Relationships and Element Collections, bases with snippet source code and again images to get a better understanding. A section interesting is Using Different Collection Types covering Lists and Maps.

Other interesting sections are:

  • Keying by Embeddable Type
  • Keying by Entity
  • Untyped Maps (even including a valuable list about Rules for Maps and even more, a table in one page about summary of Mapping a Map)

A final section for this chapter is about Best Practices

Chapter 06: Entity Manager

And impressive and long chapter. Like the most previous chapters, this one, is based again in a lot of theory, snippet source code and valuables images. Some of the most important sections available are

  • Entity Managers (Container-Managed, Application-Managed)
  • Transaction Management (JTA, and other things, a long covering including many sub sections)
  • Entity Manager Operations (persisting, finding, removing: including cascading operations like persist, remove)

An important section is Synchronization with the Database, valuable theory available and important images included too. Therefore the follow two topics are covered deeply: Detachment and Merging

Chapter 07: Using Queries

Starting covering Java Persistence Query Language based on concrete theory and snippet source code, using the same approach to cover Filtering and Projecting Results, Joins Between Entities, Aggregate Queries and Query Parameters. Easy to follow and understand these topics

The follow section is Defining Queries covering Dynamic Query Definition and Named Query Definition with many snippet source code, easy to understand, same appreciation about Parameter Types. Some section valuable is about Working with Query Results, furthermore we have available an important approach used many times, Query Paging.

Other important section is Bulk Update and Delete based in more theory than source code. The last section of this chapter is about Query Best Practices, based in theory only

Chapter 08: Query Language

An important and key chapter for us. Starting quickly with an example data model, an image about this model is included, is not complex, but has its own difficulty since show many aspects, like association and hierarchy and others. Then a complete page about a tester class is included, interesting the code, but not very realistic.

Therefore with all this, a lot of sections are covered with concrete theory and snippet source code, like:

SELECT clause which cover

  • Combining Expressions
  • Constructor Expressions
  • Inheritance and Polymorphism

FROM clause which cover

  • Identification Variables
  • Joins deeply covered about its many approaches available (even including a discuss about IN versus JOIN)

WHERE clause which cover

  • Input Parameters
  • BETWEEN Expressions
  • LIKE Expressions
  • Subqueries
  • IN Expressions
  • Collection Expressions
  • EXISTS Expressions
  • ANY, ALL, and SOME Expressions
  • Scalar Expressions
  • Literals
  • Function Expressions (including in one page a table about the supported function expressions)
  • CASE Expressions
  • ORDER BY Clause

Other sections important covered are:

  • Aggregate Queries
  • Aggregate Functions (AVG, COUNT, MAX, MIN, SUM)
  • GROUP BY Clause
  • HAVING Clause

Therefore the example data model is applied in action throughout these topics. An interesting chapter. Valuable like quick reference

Chapter 09: Criteria API

Other key chapter, well explained. Again a lot of sections are available like the previous chapter.

Starting with an introduction of the Criteria API itself, then covering Dynamic Queries, including two pages of code with its respective explanation.

With all this the section Building Criteria API Queries is introduced, an important image is available, called Criteria API Interfaces, practically all the elements are parameterized, a table called Criteria API Query Clause Methods is available too.

Other section well covered is Query Roots and Path Expressions, a lot of theory, snippet code and many tables available, well done this approach about include these tables, very useful like reference

Other sections are covered quickly with concrete theory and snippet code like

  • Predicates
  • Literals
  • Parameters
  • Subqueries (a lot of snippet code)
  • In Expressions
  • Case Expressions
  • Function Expressions

Chapter 10: Advanced Object-Relational Mapping

This is other really important and valuable chapter. It is long too. I going to share the most important sections. The chapter start with the section Advanced Object-Relational Mapping based on concrete theory and snippet code

The follow section is Complex Embedded Objects where an image called Nested embeddables with relationships is included, therefore next, some snippet code about some Entities of this image is shown, working with @Embeddable, @Embedded and @Access, even more, the author teaches us how, Overriding Embedded Relationships.

The next section is Compound Primary Keys working with the @IdClass and overriding the equals and hashCode methods. A variation of this, we have explanation about Embedded Id Class.

An important section is Derived Identifiers, long covering, explaining some sub sections like

  • Shared Primary Key
  • Multiple Mapped Attributes

Even including a table discussion called Alternative To Derived Identifiers

Even more, we have available the sections Advanced Mapping Elements which cover Read-Only Mappings and Optionality. The other section is Advanced Relationships covering many topics like:

  • Using Join Tables
  • Avoiding Join Tables
  • Compound Join Columns
  • Orphan Removal
  • Mapping Relationship State

Other important section covered is Multiple Tables, valuable snippet code and explanation, with important images for a better understanding. Then next comes an important and valuable topic for our consideration, it is Inheritance which cover:

  • Class Hierarchies (showing an image with a hierarchy structure to be used later)
  • Mapped Superclasses
  • Transient Classes in the Hierarchy
  • Abstract and Concrete Classes
  • Inheritance Models (really well covered, valuable snippet code and images)
    • Single-Table Strategy
    • Joined Strategy
    • Table-per-Concrete-Class Strategy
    • Mixed Inheritance

Chapter 11: Advanced Topics

Another long chapter, starting explaining SQL Queries which includes many snippet code about Native Queries versus JDBC, even covering @NamedNativeQuery. Even more the follow topics are covered quickly with concrete theory and snippet code:

  • Mapping Foreign Keys
  • Multiple Result Mappings
  • Mapping Column Aliases
  • Mapping Scalar Result Columns
  • Mapping Compound Keys
  • Mapping Inheritance

An interesting topic is about Lifecycle Callbacks, well covered, many pages with interesting theory with snippet code with its respective explanation is available. Other important and valuable section is about Validation working with JSR-303, good snippet code is available and even including a table about Built-in Validation Constraints showing each constraint and its respective explanation. A valuable section.

Other important section is about Concurrency and Locking, well done, valuable theory and snippet code included for the second, covering many topics like:

  • Optimistic Locking
  • Advanced Optimistic Locking Modes
  • Optimistic Read Locking
  • Optimistic Write Locking
  • Recovering from Optimistic Failures

Short covering about source code about Pessimistic Locking but includes a good amount of theory.

Practically the last section of this chapter is about Caching, valuable theory, even including an important image about Layers of caching in JPA

Chapter 12: XML Mapping Files

A lot of snippet code and many sections available working with XML, see the TOC for a better idea. But be aware that practically this chapter show many features and options applied to work or be configured through XML.

Chapter 13: Packaging and Deployment

Shortest chapter compared with others, starting covering with the section Configuring Persistence Units, based more about theory than source code.

Other section is about Building and Deploying covering about classpaths and jars, here we have some options like EJB, Web Archive and Persistence Archive.

Schema Generation is covered, the follow topics are explained with concrete theory and source code:

  • Unique Constraints
  • Null Constraints
  • String-Based Columns
  • Floating Point Columns

Chapter 14: Testing

Starting with the section Testing Enterprise Applications, interesting theory and explaining some important terms like:

  • Unit tests
  • Integration tests
  • Functional tests
  • Acceptance tests

Then the section Unit Testing is covered, based with snippet code with this respective explanation, expansion of this topic is for example The Entity Manager in Unit Tests based on more snippet code.

After of this, covering for Integration Testing is available, again working with the Entity Manager.

A long section and important is about Transaction Management, good amount of theory and working with Container-Managed Transactions and Bean-Managed Transactions each one with this respective example about source code and respective explanation.

Chapter 15: Migration

Starting with an important section called Migrating from CMP Entity Beans, important steps instructions based on source code with its respective explanation is available, many pages used for all this.

Other important section is Leveraging Design Patterns, same approach explained like above is used again, some topics covered are:

  • Fine-Grained Transfer Objects
  • Coarse-Grained Transfer Objects
  • Session Facade
  • Data Access Object

A good amount of pages available

What I liked:

  • Valuable and a huge amount of source code!
  • A lot of theory and explanation available
  • You can read the entire book comfortably
  • Easy to understand a 99% the source code throughout the book

What I disliked:

  • Perhaps more code in some sections


More Apress Books Reviews …


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s