Java Persistence API (JPA)
Last updated
Was this helpful?
Last updated
Was this helpful?
Persistence in Java can be achieved with the Java Persistence API (JPA) which is a specification for the persistence of Java objects to any relational datastore.
JPA is an abstraction on top of Java database connectivity (JDBC).
In layman's terms:
JDBC is a standard for Database Access
JPA is a standard for ORM
JPA is a specification, and by itself cannot perform any actions. To be functional, JPA requires an implementation, also known as a persistence provider.
The main implementations available are:
EclipseLink
OpenJPA
Data Nucleus
Of those listed the one I will be learning more about is Hibernate.
Persistence metadata is required to map between Java objects and database tables. The JPA provider will use the metadata to perform the correct database operations.
There are two ways to define this metadata.
Annotations within the class
External XML file
The popular way is typically via annotations.
The annotations that you'll find in most Entity classes are:
@Entity
@Table
@Id
@GeneratedValue
@Column