The Java Persistence API
TheJava Persistence API (JPA)was introduced to Java EE in version 5 of the specification. Like its name implies, it is used to persist data to a relational database management system. JPA is a replacement for the Entity Beans that were used in J2EE. Java EE Entities are regular Java classes; the Java EE container knows these classes are Entities because they are decorated with the@Entity
annotation. Let's look at an Entity mapping to theCUSTOMER
table in theCUSTOMERDB
database:
package net.ensode.javaee8book.jpaintro.entity; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "CUSTOMERS") public class Customer implements Serializable { @Id @Column(name = "CUSTOMER_ID") private Long customerId; @Column(name = "FIRST_NAME") private String firstName; @Column(name = "LAST_NAME") private String lastName; ...