The best way to handle the LazyInitializationException

Introduction The LazyInitializationException is undoubtedly one of the most common exceptions you can get when using Hibernate. This article is going to summarize the best and the worst ways of handling lazy associations.

JPA providers market share in 2016

The survey Java Persistence API is a standard. Hence, there are multiple options to choose from: Hibernate EclipseLink OpenJPA Some applications choose not to use an ORM framework at all. For this reason, I decided to run a one-day survey on Twitter to get a glimpse on the JPA providers market share.

Fluent API entity building with JPA and Hibernate

Introduction In this article, we are going to see how we can build an entity in a fluent style API fashion when using JPA and Hibernate. The JHipster development team wants to expose a Fluent Interface entity building methods for their JPA entities, so they asked me if this is going to work with JPA and Hibernate. While JPA is rather strict about entity getters and setter, Hibernate is more lenient in this regard.

The best way to map a Composite Key with JPA and Hibernate

Introduction One of my readers asked me to help him map a Composite Key using JPA and Hibernate. Because this is a recurrent question, I decided to write a blog post in which I describe this mapping in more detail.

The best way to map a @OneToOne relationship with JPA and Hibernate

Introduction In this article, we are going to learn the best way to map a OneToOne association with JPA and Hibernate. While there are many ways you can map a one-to-one relationship with Hibernate, I’m going to demonstrate which mapping is the most efficient one from a database perspective.

How do persist and merge work in JPA

Introduction In this article, I’m going to explain how the persist and merge entity operations work when using JPA and Hibernate. When using JPA, entity state transitions are translated automatically to SQL statements. This post is going to explain when to use persist and when to use merge.

14 High-Performance Java Persistence Tips

Introduction In this article, I’m going to show you various high-performance Java Persistence optimization tips that will help you get the most out of your data access layer. A high-performance data access layer requires a lot of knowledge about database internals, JDBC, JPA, Hibernate, and this post summarizes some of the most important techniques you can use to optimize your enterprise application. 1. SQL statement logging If you’re using a framework that generates statements on your behalf, you should always validate the effectiveness and efficiency of each executed statement. A testing-time assertion… Read More

The Open Session In View Anti-Pattern

Introduction Open Session in View is an Anti-Pattern, and this post is going to demonstrate why it is so. First of all, let’s start with the Wikipedia definition of an Anti-Pattern: An anti-pattern (or antipattern) is a common response to a recurring problem that is usually ineffective and risks being highly counterproductive.

How to call PostgreSQL functions (stored procedures) with JPA and Hibernate

Introduction This article is part of a series of posts related to calling various relational database systems stored procedures and database functions from Hibernate. The reason for writing this down is because there are many peculiarities related to the underlying JDBC driver support and not every JPA or Hibernate feature is supported on every relational database.

High-Performance Java Persistence – Chapter 16 – Caching

Part 2, Chapter 16 Every new chapter of my book is released right after it’s being completed, so the reader doesn’t have to wait for the whole part to be finished to get access to new material. Table of content This chapter explains how enterprise caching works, from database internal buffers, to application-level caching, and the second-level cache offered by Hibernate.