JPA tutorial – Java Persistence API tutorial for beginners with examples online on basic, Architecture, ORM Components, Entity Managers, JPQL, Advanced Mappings, Entity Relationships, Criteria API and more.
What is JPA?
JPA refers to Java Persistence API. JPA is just a specification and several implementations are available like Hibernate, EclipseLink and Apache OpenJPA. The reference implementation of JPA is EclipseLink.
JPA is like an interface which provides a set of rules and guidelines that must be followed by its implementation. It is the JPA implementation which will provide the under the hood functionality.
For example when we use Hibernate with JPA we are actually using the Hibernate JPA implementation. The benefit of this is that we can swap out Hibernate’s implementation of JPA for another implementation of the JPA specification. When you use straight Hibernate you are locking into the implementation because other ORMs may use different methods or configurations and annotations, therefore we cannot just switch over to another ORM.
- 1. JPA provides the facility to map, store, update and retrieve data from relational databases to Java objects and vice versa.
- 2. JPA implementation is typically called persistence provider.
- 3. JPA use the persistence metadata for defining the mapping between Java objects and database tables.
- 4. JPA defines the persistence metadata by using annotations or XML or a combination of both. If both annotations and XML are used to define the persistence metadata for an entity then XML configuration overwrites the annotations configuration.
- JPA Architecture
- JPA Persistence Unit
- JPA Entity Annotation
- JPA id annotation
- JPA GeneratedValue annotation
- JPA SequenceGenerator annotation
- JPA TableGenerator annotation
- JPA Embeddable annotation
- JPA EmbeddableId annotation
- JPA Table annotation
- JPA column annotation
- JPA Transient annotation
- JPA Temporal annotation
- JPA OneToOne annotation
- JPA OneToMany annotation
- JPA ManyToOne annotation
- JPA ManyToMany annotation
- JPA NamedQuery and NamedQueries annotations
- JPA NamedNativeQuery and NamedNativeQueries annotations