Guide to the Hibernate EntityManager 1. Introduction EntityManager is a part of the Java Persistence API. Chiefly, it implements the programming interfaces and lifecycle rules defined by the JPA 2.0 specification. Moreover, we can access the Persistence Context, by using the APIs in EntityManager. In this tutorial, we’ll take a… Continue Reading hibernate-entitymanager

JPA/Hibernate Projections 1. Overview In this tutorial, we’ll learn how to project entity properties using JPA and Hibernate. 2. The Entity First, let’s look at the entity we will be using throughout this article: @Entity public class Product { @Id private long id; private String name; private String description; private… Continue Reading jpa-hibernate-projections

Hibernate Entity Lifecycle 1. Overview Every Hibernate entity naturally has a lifecycle within the framework – it’s either in a transient, managed, detached or deleted state. Understanding these states on both conceptual and technical level is essential to be able to use Hibernate properly. To learn about various Hibernate methods… Continue Reading hibernate-entity-lifecycle

Difference Between @Size, @Length, and @Column(length=value) 1. Overview In this quick tutorial, we’ll take a look at JSR-330‘s @Size, Hibernate‘s @Length and JPA @Column‘s length attribute. At first blush, these may seem the same, but they perform different functions. Let’s see how. 2. Origins Simply put, all of these annotations… Continue Reading jpa-size-length-column-differences

Hibernate 5 Naming Strategy Configuration 1. Overview Hibernate 5 provides two different naming strategies for use with Hibernate entities: an Implicit Naming Strategy and a Physical Naming Strategy. In this tutorial, we’ll see how to configure those naming strategies to map entities to customized table and column names. For readers… Continue Reading hibernate-naming-strategy

Hibernate Second-Level Cache 1. Overview One of the advantages of database abstraction layers such as ORM (object-relational mapping) frameworks is their ability to transparently cache data retrieved from the underlying store. This helps eliminate database-access costs for frequently accessed data. Performance gains can be significant if read/write ratios of cached… Continue Reading hibernate-second-level-cache

Batch Insert/Update with Hibernate/JPA 1. Overview In this tutorial, we’ll look at how we can batch insert or update entities using Hibernate/JPA. Batching allows us to send a group of SQL statements to the database in a single network call. This way, we can optimize the network and memory usage… Continue Reading jpa-hibernate-batch-insert-update