Summary
A key component of Java EE 5 is the Java Persistence API (JPA) that provides an object-relational mapping framework for enterprise applications. Although formally part of the EJB 3 spec, the JPA can be used stand-alone. In a recent java.net article, Josh Marinacci shows how to use JPA from a simple client-side application.
Advertisement
The Java Persistence API (JPA) occupies its own specification document within the broader EJB 3 spec. That separation highlights the fact that the JPA can be used outside a full EJB 3 container. Becase the JPA distills the best object-relational mapping and persistence ideas from a host of enterprise persistence frameworks, the JPA is now one of the most effective ways to access a relational database from even client-side Java applications.
Josh Marinacci's java.net article, An Introduction to Java Persistence for Client-Side Developers, provides an introductory JPA tutorial that those with little JPA familiarity will find especially helpful. The article assumes no Java EE knowledge—indeed, the JPA architecture itself delegates much of the heavy lifting to persistence providers, such as Hibernate, and reduces complexity by relying on sensible API defaults. In this example, only two JPA annotations, a single XML configuration file, and a few lines of extra code are used to persist a POJO from a client application. The annotations are as simple as the following:
@Entity
public class Person {
@Id @GeneratedValue
public Long id;
public String first;
public String middle;
public String last;
}
While object-relational mapping is not appropriate for all applications, the JPA makes this technique a standard accessible to any Java application via an easy-to-use API. Do you envision yourself using the JPA even outside an EJB 3 container?