OpenJPA is the open source implementation of Java Persistence API. It has been integrated with the Weblogic, WebSphere, and Geronimo application servers. JPA provides an agnostic Java-based API for storing and retrieving information to a backend database. It has a canonical query language named Java Persistence Query Language, or JPQL, that blends with the programming methods of Java and eliminates the need to tailor database queries for a particular database. However, JPA also supports native SQL which can be used for quick ports with a known backend database.
You'll need three artifacts to implement a JPA-compliant program:
- An entity class
- A persistence.xml file
- A class through which you will insert, update, or find an entity
- JPA allows persistent classes to inherit from non-persistent classes, persistent classes to inherit from other persistent classes, and non-persistent classes to inherit from persistent classes.
- The entity class should have a default no-argument constructor.
- The entity class should not be final.
- Persistent classes cannot inherit from certain natively-implemented system classes such as
java.net.Socket
andjava.lang.Thread
. - If a persistent class inherits from a non-persistent class, the fields of the non-persistent super class cannot be persisted.
-
@PostLoad
-
@PrePersist
-
@PostPersist
-
@PreUpdate
-
@PostUpdate
-
@PreRemove
-
@PostRemove