How to map a composite identifier using an automatically @GeneratedValue with JPA and Hibernate

Introduction One of my readers asked me to answer the following StackOverflow question. While I already covered the best way to map composite identifiers with JPA and Hibernate, this use case is different because one column is automatically generated.

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

Introduction In this article, I’m going to show you the best way to map a DTO projection when using JPA and Hibernate. 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… Read More

The best way to implement an audit log using Hibernate Envers

Introduction In this article, we are going to learn what is the best way to implement an audit log to track INSERT, UPDATE, and DELETE statements using Hibernate Envers. 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… Read More

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.

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 into a blog post. In this article, you are going to see how you can use JSON types to store schema-less EAV data.

How to optimize the merge operation using update while batching with JPA and Hibernate

Introduction One of my readers has recently asked me about optimizing the merge entity state transition, and, because this is a great question, I decided to turn it into a blog post. In this article, you are going to see a shortcoming of the merge entity state transition and how you can deal with it using Hibernate.

The best way to map a JPA and Hibernate many-to-many association with extra columns

Introduction For a simple many-to-many database relationship, you can use the @ManyToMany JPA annotation and, therefore, hide the join table. However, sometimes you need more than the two Foreign Key columns in the join table, and, for this purpose, you need to replace the @ManyToMany association with two bidirectional @OneToMany associations. Unlike unidirectional @OneToMany, the bidirectional relationship is the best way to map a one-to-many database relationship that requires a collection of Child elements on the parent side In this article, we are going to see how you can map a many-to-many… Read More

How to extract change data events from MySQL to Kafka using Debezium

Introduction As previously explained, CDC (Change Data Capture) is one of the best ways to interconnect an OLTP database system with other systems like Data Warehouse, Caches, Spark or Hadoop. Debezium is an open-source project developed by Red Hat which aims to simplify this process by allowing you to extract changes from various database systems (e.g. MySQL, PostgreSQL, MongoDB) and push them to Apache Kafka. In this article, we are going to see how you can extract events from MySQL binary logs using Debezium.

Book Review – High Performance MySQL (3rd edition)

Introduction I either have time for reading or writing, but not both. Now that the first edition of High-Performance Java Persistence is done, I can catch up on the many books I planned on reading but didn’t have time to do so. In this post, I’m going to review High Performance MySQL by Baron Schwartz, Peter Zaitsev, and Vadim Tkachenkoa, which is a must-read book for anyone working with MySQL.