Chapter 9. Persistence: EntityManager
Persistence is a key piece of the Java EE platform. In older versions of J2EE, the EJB 2.x specification was responsible for defining this layer. In Java EE 5, persistence was spun off into its own specification. Now, in EE6, we have a new revision called the Java Persistence API, Version 2.0, or more simply, JPA.
Persistence provides an ease-of-use abstraction on top of JDBC so that your code may be isolated from the database and vendor-specific peculiarities and optimizations. It can also be described as an object-to-relational mapping engine (ORM), which means that the Java Persistence API can automatically map your Java objects to and from a relational database. In addition to object mappings, this service also provides a query language that is very SQL-like but is tailored to work with Java objects rather than a relational schema.
In short, JPA handles the plumbing between Java and SQL. EJB provides convenient integration with JPA via the entity bean.
Entity beans, unlike session and message-driven types, are not
server-side components. Instead, they are simple objects whose state can be
synchronized with an underlying persistent storage provider. They are
created just like any normal instance, typically using the new
operator, and have no special APIs that must be
implemented by the Entity class.
Much like EJB’s server-side types, however, entity beans gain powerful services when used within the context of the container. In the case of persistence, ...
Get Enterprise JavaBeans 3.1, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.