What’s new in JPA 2.2 – Stream the result of a Query execution

Introduction

Now that the JPA 2.2 Review Ballot was approved, let’s start analyzing some of the new additions to the standard which have been supported by Hibernate for quite some time already.

In this article, we are going to see how Stream query results are supported by Hibernate and the caveats of using database cursors just to limit the amount of data that needs to be fetched.

Continue reading “What’s new in JPA 2.2 – Stream the result of a Query execution”

Advertisements

What’s new in JPA 2.2 – Java 8 Date and Time Types

Introduction

Now that the JPA 2.2 Review Ballot was approved, let’s start analyzing some of the new additions to the standard which have been supported by Hibernate for quite some time already.

In this article, we are going to see how Java 8 Date/Time API is supported and which types you need to use depending on your business case requirements.

Continue reading “What’s new in JPA 2.2 – Java 8 Date and Time Types”

How to map Java and SQL arrays with JPA and Hibernate

Introduction

Hibernate custom Types allow you to map all sorts of database specific column types, like IP address, JSON columns, bit sets or SQL arrays.

There are two ways to define a custom Hibernate Type:

The latter option is preferred since it allows you to better split the Java-to-JDBC and the JDBC-to-SQL type handling. In this article, we are going to see how you can map SQL arrays to their Java counterpart.

Continue reading “How to map Java and SQL arrays with JPA and Hibernate”

The best way to use entity inheritance with JPA and Hibernate

Introduction

Recently, my friend Lukas Eder wrote the following message on Twitter:

Just like in any OOP (Object-Oriented Programming) language, entity inheritance is suitable for varying behavior rather than reusing data structures, for which we could composition. The Domain Model compromising both data (e.g. persisted entities) and behavior (business logic), we can still make use of inheritance for implementing behavioral software design pattern.

In this article, I’m going to demonstrate how to use JPA inheritance as a means to implement the Strategy design pattern.

Continue reading “The best way to use entity inheritance with JPA and Hibernate”

The best way to map the SINGLE_TABLE inheritance with JPA and Hibernate

Introduction

Java, like any other object-oriented programming language, makes heavy use of inheritance and polymorphism. Inheritance allows defining class hierarchies that offer different implementations of a common interface.

Conceptually, the Domain Model defines both data (e.g. persisted entities) and behavior (business logic). Nevertheless, inheritance is more useful for varying behavior rather than reusing data (composition is much more suitable for sharing structures).

Even if the data (persisted entities) and the business logic (transactional services) are decoupled, inheritance can still help varying business logic (e.g. Visitor pattern).

In this article, we are going to see what is the best way to map the SINGLE_TABLE inheritance, which, not only is the default inheritance strategy, but it’s usually the most efficient way to model entity inheritance.

Continue reading “The best way to map the SINGLE_TABLE inheritance with JPA and Hibernate”