- Full Description
Pro JPA 2 introduces, explains, and demonstrates how to use the Java Persistence API (JPA). JPA provides Java developers with both the knowledge and insight needed to write Java applications that access relational databases through JPA.
Authors Mike Keith and Merrick Schincariol take a handson approach to teaching by giving examples to illustrate each concept of the API and showing how it is used in practice.All of the examples use a common model from an overriding sample application, giving readers a context from which to start and helping them to understand the examples within an already familiar domain.
After completing the book, you will have a full understanding and be able to successfully code applications using JPA. The book also serves as a reference guide during initial and later JPA application experiences.
- Hands-on examples for all the aspects of the JPA specification, based on the reference implementation of this specification
- A special section on migration to JPA
- Expert insight about various aspects of the API and when they are useful
- Portability hints to provide increased awareness of the potential for nonportable JPA code
What youll learn
- Get started with enterprise applications using JPA 2
- Get up to speed with objectrelational mapping and Entity Manager
- Learn and use queries and the query language (JP QL)
- Employ advanced objectrelational mapping techniques
- Use XML mapping files and learn other advanced techniques
- Package and deploy your Java persistence applications
- Test your Java persistence applications
- Migrate your Java persistence applications
Who this book is for
The book generally targets enterprise and persistence developers who fall in one of three categories:
- Those who are new to persistence; we will present some background information and introduce these readers to the basic persistence concepts to bring them up to speed.
- Those who know and/or use existing ORM persistence products such as Hibernate or TopLink.
- Those who have already used JPA and want to learn about newer features introduced by JPA 2, or have a good reference book to consult when they develop JPA applications.
In general, we assume that the reader is knowledgeable with Java, SQL, and JDBC, and has a little knowledge of J2EE.
- Table of Contents
Table of Contents
- Getting Started
- Enterprise Applications
- Object-Relational Mapping
- Collection Mapping
- Entity Manager
- Using Queries
- Query Language
- Criteria API
- Advanced Object-Relational Mapping
- Advanced Topics
- XML Mapping Files
- Packaging and Deployment
- Source Code/Downloads
If you think that you've found an error in this book, please let us know about it. You will find any confirmed erratum below, so you can check if your concern has already been addressed.On page 38:listing 3, implement Logger should be extends Logger, it conflicts with the Logger.getLogger("Notification") line in the same list.
On page 50:
On line 29 , the injected EJB reference should be
but it is given
The full reference name is
On page 59:
"defined on java.transaction.Status" must read "defined on javax.transaction.Status"
On page 96:
The author references Figure 4-15 in the text, but I think he actually meant Figure 4-14.Author Comment:
On page 99:Figure 4-16: the left table must be EMPLOYEE, not PROJECT
On page 207:In Chapter 8: Query Language, the jpqlExamples WAR has this query:
SELECT e, COUNT(p)
FROM Employee e JOIN e.projects p
GROUP BY e
HAVING COUNT(p) >= 2
When executed, the following error occurs:
java.lang.IllegalArgumentException: An exception occurred while creating a
query in EntityManager:
Exception Description: Error compiling the query [SELECT e, COUNT(p) FROM
Employee e JOIN e.projects p GROUP BY e HAVING COUNT(p) >= 2], line 1, column 80: invalid HAVING expression [COUNT(p) >= 2] for query with grouping [GROUP BY e]. The HAVING clause must specify search conditions over the grouping items or aggregate functions that apply to grouping items.
A EclipseLink bug was filed:
and the bug was closed with this comment:
Section 4.7 of the JPA 2.0 specification disallows using elements in the HAVING
clause that are not in the GROUP BY clause. I suggest raising an errata against the book.Author Comment:
On page 207:
In Chapter's 8 examples source code there's an error in mapping between Employee and Phone entities. On the Employee's entity side the mapping is written well, but on the Phone's entity side it should be @ManyToOne instead of @OneToOne above the 'employee' field.
On page 261:
I found two issues in Chapter 9 criteria api, at the top of page 261:
1) The identification variable d in:
SELECT avg(d.salary) FROM e.directs is not defined.
2) The select clause of this same part of the query which is translated into a criteria query is missing in the criteria version also on top of page 261
On page 323:
The query on the top of the page with two left joins seems to be wrong based on the domain model in fig 8-1.
On page 340:
ConstraintPaload got renamed into Payload for the final release of the Bean Validation spec.Author Comment:
On page 367:
In example: q.setProperty("javax.*", ..);
setProperty is not a valid method for the TypedQuery<?> q.Author Comment:
On page 373:Page 373, the xsd URL for JPA2 is incorrect. The link comes up as 404 not found.Author Comment: