jpa

JPA mappedBy Example

Hello readers, in this tutorial, we will show how to implement the mappedBy annotation in JPA using EclipseLink and MySQL in Java. 1. Introduction Java Persistence API (JPA), is a standard interface which wraps the different Object Relational Mapping (ORM) tools such as Hibernate, EclipseLink, OpenJPA etc. JPA provides a javax.persistence.EntityManager interface which is used to interact with the database. ...

Read More »

JPA persistence.xml Example

Hello readers! In this tutorial we will show how to implement the Java Persistence API and define the JPA Persistence Units with EclipseLink and MySQL in Java. 1. Introduction Java Persistence API (JPA), is a standard interface which wraps the different Object Relational Mapping (ORM) tools such as Hibernate, EclipseLink, OpenJPA etc. JPA provides a javax.persistence.EntityManager interface which is used ...

Read More »

JPA CriteriaBuilder Example

The Criteria API is a predefined API used to define queries for entities. It is the alternative way of defining a JPQL query. These queries are type-safe, portable and easy to modify by changing the syntax i.e. the JPA queries are mainly used for building the dynamic queries whose exact structure is only known at the runtime. In this tutorial, ...

Read More »

JPA Relationship Annotations Example

Here we will look into the JPA Relationship Annotations. This article takes you through the relationships between Entities. Generally the relations are more effective between tables in the database and as We already know that in RDBMS every entity(table) must be related to other entities to become meaningful. Here the entity classes are treated as relational tables (concept of JPA). ...

Read More »

JPA Native SQL Queries Example

In this example, we shall see how to use native SQL queries in JPA. The Java Persistence Query Language is a powerful query language that can be used to bridge the Object Relational world. However, there are cases when the JPQL falls short for example, to execute a Stored Procedure. The JPA optimizes the query written in JPQL for the ...

Read More »

JPA SQL Stored Procedure Example

Here we will discuss about the JPA SQL Stored Procedures, i.e. using database Stored Procedures from JPA (Java Persistance API) along with Cursors, Multiple Parameters (IN & OUT) etc. We have used EclipseLink for our project. However this can also be done with other JPA providers such as Hibernate, Toplink, Spring Data JPA, etc. JPA 2.1 supports calling database stored procedures ...

Read More »

JPA EntityManager Example

In this example, we shall try to demonstrate how to use JPA EntityManager. As the name suggests, an EntityManager is a class that manages the state of the Entity(Persist/Update/Delete etc). Every EntityManager object has an instance of EntityTransaction associated with it. EntityTransaction is used to manage the transactions. We shall be using Hibernate as the JPA Vendor. The underlying database ...

Read More »

Map Java Enum type in JPA

In this example we shall show you how to map a Java Enum type in JPA. The Java Persistence API provides Java developers with an object/relational mapping facility for managing relational data in Java applications. Here, we map a Java Enum implementation in JPA, as described below: An entity class An entity is a lightweight persistence domain object. Typically, an ...

Read More »

Embedded compound primary key in JPA

With this example we are going to demonstrate how to create an embedded compound primary key in JPA. The Java Persistence API provides Java developers with an object/relational mapping facility for managing relational data in Java applications. A composite primary key is usually made up of two or more primitive or JDK object types. Composite primary keys typically arise when ...

Read More »

Named query with entity in JPA

This is an example of how to create a named query with an entity in JPA. The Java Persistence API provides Java developers with an object/relational mapping facility for managing relational data in Java applications. A named query is a predefined query that you create and associate with a container-managed entity. The named queries are stored on the EntityManager. At ...

Read More »