The best way to map a projection query to a DTO (Data Transfer Object) with JPA and Hibernate

Introduction

While answering questions on the Hibernate forum, I stumbled on the following question. What was different than previous questions on the same topic was that the original poster realized the shortcoming of the JPA constructor expression which can be addressed elegantly by Hibernate.

Because this has been a recurring theme on StackOverflow and the Hibernate forum, I decided to dedicate an article to the best way of mapping DTO projections using JPA and Hibernate.

Continue reading “The best way to map a projection query to a DTO (Data Transfer Object) with JPA and Hibernate”

Advertisements

The best way to implement an audit log using Hibernate Envers

Introduction

As previously explained, CDC (Change Data Capture) is an essential step to extract change events from an OLTP application to make them available to other modules in an enterprise system (e.g. caches, data warehouse).

While Debezium is the most efficient way of doing CDC, it might be that you need a simpler solution in your project. Hibernate Envers is a Hibernate ORM extension that allows you to capture change events in no time.

In this article, we are going to see the most efficient way of using Hibernate Envers.

Continue reading “The best way to implement an audit log using Hibernate Envers”

How to map a @ManyToOne association using a non-Primary Key column with JPA and Hibernate

Introduction

While answering questions on the Hibernate forum, I stumbled on the following question about using the @ManyToOne annotation when the Foreign Key column on the client side references a non-Primary Key column on the parent side.

In this article, you are going to see how to use the @JoinColumn annotation in order to accommodate non-Primary Key many-to-one associations.

Continue reading “How to map a @ManyToOne association using a non-Primary Key column with JPA and Hibernate”

How to store schema-less EAV (Entity-Attribute-Value) data using JSON and Hibernate

Introduction

One of my Twitter followers has recently asked me about a way of storing EAV (Entity-Attribute-Value) data using JPA and Hibernate, and, because this is a very good question, I decided to turn answer it using a blog post.

In this article, you are going to see how you can use JSON types to store schema-less EAV data.

Continue reading “How to store schema-less EAV (Entity-Attribute-Value) data using JSON and Hibernate”