Home » jpa » Page 2

Tag Archives: jpa

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 »

JSF JPA CRUD Tutorial

Hello, in this tutorial I would like to show the usage of JPA (Java Persistence API’s) in a simple jsf application and will demonstrate the following: Schools List Performing database operations using JPA framework Sending & retrieving data to & from a managed bean This example will show the implementation of basic CRUD (Create, Read, Update, Delete) operations and lets ...

Read More »

20 Spring Framework Best Practices

Spring Application Framework has been in action for quite a long time, and programmers have developed several conventions, usage patterns, and idioms during that time period. In this example, we will try to explain some of them and give examples to illustrate how to apply them in your projects. Let’s begin. Table Of Contents 1. Define singleton beans with names ...

Read More »

Spring Data JPA Example

The goal of Spring Data repository abstraction is to significantly reduce the amount of boilerplate code required to implement data access layers for various persistence stores. If we try to implement a data access layer of an application on our own, we will end up with lots of boilerplate code. Spring provides JPA module which not only eliminates boilerplate code ...

Read More »

JPA Named Query Example

1. Introduction In this article you will learn how to use the JPA @NamedQuery and @NamedNativeQuery annotations. We will start by introducing some general aspects about named queries, then creating simple examples, using both JPQL and native SQL queries, passing parameters to named queries and using vendor-specific query hints. You will then learn how to execute named queries and use ...

Read More »

JPA One-to-One Example

1. Introduction In this article we will explore the JPA @OneToOne association in a SQL and NoSQL fashion. A @OneToOne association occurs when there is exactly one record in a table that corresponds to exactly one record in a related table. In this case, both tables will contain the same number of records and each row of the first table ...

Read More »

JPA One-to-Many Example

1. Introduction In this article we will explore the JPA @OneToMany and @ManyToOne associations in a SQL and NoSQL fashion. A @OneToMany association occurs when each record in one table corresponds to multiple records in a related table. If the records from the second table have an inverse association back to the first table, we say that we have a ...

Read More »

Hibernate JPA DAO Example

This is an example of how to create Data Access Objects (DAOs), making use of the Hibernate implementation for the Java Persistence API (JPA) specification. Hibernate is an object-relational mapping library for Java, that provides a framework for mapping an object-oriented domain model to a traditional relational database. When an application interacts with a database, it is common pattern to ...

Read More »