jpa

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 »

Single table inheritance in JPA

In this example we shall show you how to create a single table inheritance in JPA. The Java Persistence API provides Java developers with an object/relational mapping facility for managing relational data in Java applications. Here we shall show you how to use inheritance in JPA. Manager and ProjectManager classes The Manager class is an abstract class, that uses the ...

Read More »

One To Many bidirectional mapping in JPA

With this example we are going to demonstrate how to use One to Many bidirectional mapping in JPA. The Java Persistence API provides Java developers with an object/relational mapping facility for managing relational data in Java applications. Here, we are using the JPA to define a one to many bidirectional mapping between two entities. The Employee class The Employee class ...

Read More »

One To Many unidirectional mapping in JPA

This is an example of how to use One to Many unidirectional mapping in JPA. The Java Persistence API provides Java developers with an object/relational mapping facility for managing relational data in Java applications. Here, we are using the JPA to define a one to many unidirectional mapping between two entities. Employee Class and Phone Class The Employee class is ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns