~/devreads

#hibernate

81 posts

27 Feb

vladmihalcea 1 min read

Introduction In this article, I’m going to show you how to emulate a LEFT JOIN FETCH between two root entities without fetching the intermediate child entity. I got the inspiration for this article by this comment thread on my blog. Domain Model Let’s assume we have the following entities: The Post is the root entity of our hierarchy, but just…

hibernatefetchjoin fetchunrelated

2 Dec 2025

vladmihalcea 1 min read

Introduction In this article, I’m going to show you the best way to replace the deprecated @GenericGenerator when upgrading your application to Hibernate 7. Hibernate @GenericGenerator annotation The @GenericGenerator annotation has been available since Hibernate 3.5, as an alternative to the <generator> XML element from HBM mappings. As illustrated by the Hibernate 6.5 @GenericGenerator Javadoc, this annotation was deprecated in…

hibernatedatabase identifierdeprecatedgenericgeneratoridentifier

11 Nov 2025

vladmihalcea 1 min read

Introduction In this article, I’m going to show you the best way to clean up test data when using Spring and Hibernate. While it’s very common to use the @DataJpaTest annotation when implementing integration tests, in this blog post, you will see why you are better off avoiding using this annotation. Why I don’t use @DataJpaTest As explained by the…

hibernatespringcleanupintegration testingjpa

18 Mar 2025

vladmihalcea 1 min read

Introduction In this article, I’m going to explain how to map the Oracle TIMESTAMP WITH TIME ZONE with JPA and Hibernate. While the DATE and TIMESTAMP column types are suitable for mapping the LocalDateTime, the TIMESTAMP WITH TIME ZONE column type allows us to map both the ZonedDateTime and OffsetDateTime. Oracle TIMESTAMP WITH TIME ZONE Traditionally, Oracle provided the DATE…

hibernatejpaoffsetdatetimeoracletimezone

12 Dec 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this series of articles from Franck Pachot about Amazon Aurora Limitless, a PostgreSQL-compatible database that provides…

newsletterhibernatejavajpamysql

26 Nov 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see why there is no benefit in using the Set collection type when mapping a bidirectional JPA OneToMany association. While the @OneToMany annotation can be used to map both unidirectional and bidirectional associations, as I explained this article, you should avoid the unidirectional mapping since it can lead to very inefficient SQL…

hibernateonetomanybidirectionalentityequals

14 Nov 2024

vladmihalcea 1 min read

Introduction In this article, we are going to analyze how the JTA transaction type works. Since this is the default transaction type when using Jakarta EE or Java EE applications, it’s very important to understand how JTA transactions work, especially since Spring Boot or Spring applications use RESOURCE_LOCAL transactions instead. JTA Transaction Type When using the JTA transaction type, you…

hibernatespringtransactionsjpajta

1 Nov 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this article about data alignment in PostgreSQL tables and indexes. By properly designing your tables and…

newsletterhibernatejavajpamysql

14 Oct 2024

vladmihalcea 1 min read

Introduction In this article, we are going to analyze how the RESOURCE_LOCAL JPA transaction type works. Since this is the default transaction type when using Spring Boot or Spring Data JPA, it’s very important to understand how transactions are managed when using the RESOURCE_LOCAL mode. JPA Transaction Types When the JPA 1.0 specification was released, there were two transaction types…

hibernatespringjparesource localtransactions

7 Oct 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this article about B+Tree indexes, which features a live tool that we can use to see…

newsletterhibernatejavajpamysql

19 Sept 2024

vladmihalcea 1 min read

Introduction In this article, we are going to investigate the Spring Data Envers project and see how to get the best out of it. Hibernate Envers is a Hibernate ORM extension that allows us to track entity changes with almost no changes required on the application part. Just like Envers plugs into Hibernate ORM in order to build an audit…

springauditenvershibernatejpa

10 Sept 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can map embeddable inheritance when using JPA and Hibernate. The feature described in this article is available since version 6.6 of Hibernate ORM, so if you haven’t yet upgraded, then you have one more reason to consider it. Domain Model Let’s consider we have the following Subscriber entity that…

hibernateembeddablehibernate embeddableinheritancejpa

2 Sept 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this article about the difference between the ON CONFLICT clause and the MERGE statement when using…

newsletterhibernatejavajpamysql

26 Aug 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can create a custom Spring Boot Actuator endpoint in order to export our own metrics and events. Spring Boot Actuator is a Spring Boot module that provides support for tracing and monitoring. And, while by default, we get various health checks and metrics, we are not limited to the…

hibernate

19 Aug 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can integrate Jakarta Data with Spring and Hibernate. Jakarta Data is a new Jakarta EE specification that provides a common API for building data Repositories and data access objects. If you are familiar with Spring Data JPA, you will see that Jakarta Data is very much inspired by this…

hibernatespringjakarta datajpaspring data

6 Aug 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this article about various online schema migration options that are available in MySQL. Another great read…

newsletterhibernatejavajpamysql

30 Jul 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can use the Hibernate SoftDelete annotation to activate soft deleting for JPA entities. While, as I explained in this article, you can manually implement the soft delete mechanism using the @SQLDelete, @Loader and @Where annotations, it’s definitely much easier to just use the native Hibernate mechanism introduced in Hibernate…

hibernatedeletesoft delete

2 Jul 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this article about the drawbacks of using natural keys. Speaking of mapping tables, if you need…

newsletterhibernatejavajpapostgresql

24 Jun 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can map Java Enum to custom values when using JPA and Hibernate. While Hibernate provides several options to save Enum values, having the option to customize this mechanism is even better, as it will allow you to better deal with legacy applications or use cases that require you to…

hibernatecustomenumjpa

18 Jun 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how the Hibernate JAVA_TIME_USE_DIRECT_JDBC setting works and what JDBC Driver supports this feature. This setting can be set programmatically, as illustrated by the following Spring Java-based configuration: Or you can set it declaratively in the Spring Boot application.properties configuration file like this: Domain Model To test how the Hibernate JAVA_TIME_USE_DIRECT_JDBC setting…

hibernatejdbclocaldatetimeoffsetdatetimesetting

13 Jun 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how the Hibernate WITH RECURSIVE query works and how we can use it to fetch hierarchical data structures. Domain Model Let’s consider we have the following post and post_comment tables: The post_comment child table has a one-to-many table relationship with the parent post table via the post_id Foreign Key column in…

hibernatecterecursivewith

4 Jun 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this article from Gergely Orosz about designing and scaling Bluesky. You will learn about favoring flexibility,…

newsletterhibernatejavajpapostgresql

29 May 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how the Hibernate ON CONFLICT DO clause works, and how we can use it to execute an SQL UPSERT statement in a portable way. Upsert As I explained in this article, if you have this use case where you need to either INSERT or UPDATE a table record based on whether…

hibernatejpamergemysqlon conflict

8 May 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how you can override the FetchType.EAGER strategy using the fetchgraph query hint. While this feature has been available in the JPA specification since version 2.1, Hibernate has only supported this feature since version 5.5. JPA FetchType.EAGER and FetchType.LAZY strategies The fetching strategy can be specified either at the entity mapping level…

hibernateentity graphfetchgraphjpa

2 May 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this article which describes how bandwidth, latency, IOPS, and jitter works in a relational database system.…

newsletterhibernatejavajpamysql

24 Apr 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see what is the best way we can use OneToOne optional attribute so that we can avoid N+1 query issues. One-To-One table relationship As I explained in this article, in a one-to-one table relationship, the parent and the child tables share the Primary Key column values because the child table Primary Key…

hibernateonetoonebidirectionaljpaoptional

3 Apr 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this article about Jakarta Persistence 3.2, which brings a lot of improvements to the JPA specifications,…

newsletterhibernatejavajpapostgresql

4 Mar 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this article about using the BUFFERS option in the PostgreSQL EXPLAIN ANALYZE so that we can…

newsletterhibernatejavajpamysql

27 Feb 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can map the OffsetDateTime ZoneOffset with the Hibernate TimeZoneColumn annotation. As I explained in this article, by default, Hibernate doesn’t store the time-zone offset of an OffsetDateTime entity attribute in a separate column. Instead, the OffsetDateTime is stored as a java.time.Instant that is relative to the UTC time zone.…

hibernate

24 Feb 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can use Java Records with Spring Data JPA Repositories. As I already explained, Java Records cannot be used as JPA entities since the Records are immutable, and JPA requires the entity class to have a default constructor and be modifiable, as that’s how the entity properties are populated when…

hibernatespringjavajparecords

7 Feb 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can use the Hibernate StatelessSession in order to enable JDBC Batching for INSERT, UPDATE, and DELETE statements. While the StatelessSession has been available for more than 20 years, until Hibernate 6, its usefulness was rather limited since it lacked support for batching, as well as other cool features, such…

hibernatebatchjdbcstatelesssession

1 Feb 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week is this article written by Lukas Eder about various query optimizations the database can do to speed…

newsletterhibernatejavajpamysql

24 Jan 2024

vladmihalcea 1 min read

Introduction In this article, we are going to see how to fetch recursive associations when using JPA and Hibernate. Recursive table relationships are built using self-referencing Foreign Key columns so that a record in a table can reference another record in the very same table, therefore allowing us to represent hierarchical structures using the relational model. Domain Model Let’s consider…

hibernateassociationjparecursive

3 Jan 2024

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this series of articles about transaction isolation levels in PostgreSQL. Speaking of database transactions, this article…

newsletterhibernatejavajpamysql

19 Dec 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how the Hibernate StatelessSession Upsert method works. As I explained in this article, the UPSERT operation allows you to INSERT a record if there is no such record matching the filtering criteria or to UPDATE it in case the record exists. While many relational database systems offer the standard MERGE command…

hibernatemysqloraclepostgresqlsql server

15 Dec 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see what is the best way to map multiple entities on the same table. There are several advantages to mapping multiple entities on the same database table: To avoid loading large columns (e.g., JSON) To avoid N+1 query issues for bidirectional @OneToOne associations Before we start investigating the best way to map…

hibernateonetoonejpamultiple entities

7 Dec 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how Spring load-time weaving works so that you can apply the Hibernate bytecode enhancement mechanism at runtime. Traditionally, the bytecode enhancement mechanism is applied when the project is built using a Maven or Gradle plugin. For more details about the build-time approach, check out this article. Domain Model Let’s consider we…

hibernatespringbytecode enhancemententityinstrumentation

1 Dec 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article about PostgreSQL double buffering. Hibernate 6.3 added support for table partitioning, and in this…

newsletterhibernatejavajpapostgresql

15 Nov 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can cascade the DELETE operation for unidirectional associations with Spring Data JPA and Hibernate events. Using Hibernate events to achieve this goal is an alternative to the bulk DELETE statement strategy, as it allows us to cascade the delete operation from a parent entity to its children when we…

hibernatespringcascadedeleteevent

9 Nov 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can implement a table partitioning solution when using Spring and Hibernate. The goal of table partitioning is to split a large table into multiple smaller partition tables so that the associated table and index records can fit into the in-memory Buffer Pool, therefore allowing a more efficient seek or…

hibernatespringpostgresqltable partitioning

1 Nov 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article about MySQL 8.2 automatic read and write routing. Until MySQL 8.2 is released, if…

newsletterhibernatejavajpapostgresql

18 Oct 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can batch INSERT statements when using MySQL and Hibernate. While Hibernate has long supported automated JDBC batch inserts, this feature doesn’t work when using the IDENTITY identifier generator strategy. Unfortunately, MySQL doesn’t support SEQUENCE objects, so using IDENTITY is the only reasonable option. Therefore, I’m going to show you…

hibernatespringbatchbatch insertjpa

3 Oct 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article that marks the 10-year anniversary of this blog. For over a decade, I managed…

newsletterhibernatejavajpapostgresql

20 Sept 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can find the source of an SQL query generated by Hibernate. Knowing where a given SQL query originates from is very useful when trying to investigate performance issues caused by either long-running queries or queries that are executed excessively (e.g., N+1 query issues). Hypersistence Utils This feature that we…

hibernatequerysqlstacktrace

13 Sept 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can fetch multiple JPA entity collections without generating an implicit Cartesian Product with the MULTISET strategy offered by the Blaze Persistence open-source project. The MULTISET fetch strategy is inspired by the MULTISET operator offered by jOOQ. If you are not familiar with the MULTISET operator, then check out this…

hibernatespringblaze persistencecollectionjpa

5 Sept 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article, which explains how you can use the Hibernate Statistics in order to assert the…

newsletterhibernatejavajpamysql

22 Aug 2023

vladmihalcea 1 min read

Introduction In this article, I’m going to show you the best way to hide the JPA entity identifier so that the users of your application won’t be able to guess and access data that belongs to other users. This has been a recurring question that I’ve been getting when running training or workshops, so I decided it’s a good idea…

hibernatehideidentifierjpamasquerade

16 Aug 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see what are the best way to use JPA bidirectional sync methods for one-to-many, one-to-one, and many-to-many associations. For an introduction to why you need sync methods for your bidirectional JPA associations, check out this article first. Domain Model For this article, we are going to use the following entities that are…

hibernatebidirectionaljpasync

2 Aug 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article, which explains how the standard PostgreSQL MVCC system works and how the OrioleDB engine…

newsletterhibernatejavajpamysql

21 Jul 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can implement a soft delete mechanism when the JPA entity features a version property. If you are not using a version property for optimistic locking, then you can implement the soft delete strategy, as explained in this article. Domain Model Let’s assume we have the following Post, PostDetails, PostComment,…

hibernatedeletejpaoptimistic lockingsoft delete

11 Jul 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how to customize the HibernateTypesContributor from Hypersistence Utils so that we can disable all or filter out certain Types. What does HibernateTypesContributor does in Hypersistence Utils The HibernateTypesContributor implements the TypeContributor Hibernate interface and registers several Types automatically. By doing this, the audited entities will be able to locate the Hypersistence…

hibernatehypersistence utilstype

4 Jul 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article, which provides a very thorough explanation of how queries are executed and how you…

newsletterhibernatejavajpamysql

14 Jun 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see what is the best way to use one-to-one table relationships. I decided to write this article after reading this Tweet: One-to-one table relationships As I explained in this article, a relational database system defines three table relationship types: one-to-many one-to-one many-to-many The one-to-one table relationships rely on the fact that both…

hibernatesqlonetooneone-to-onetable relationship

7 Jun 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see what is the best way to validate the DDL schema and the JPA entity mappings when using Spring and Hibernate. I decided to write this article after reading this Tweet: The hbm2ddl validate strategy As I explained in this article, Hibernate provides a SchemaManagementTool that we can use to manage or…

hibernatespringhbm2ddljpavalidation

31 May 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article which explains why performance engineering is not just about solving a few bottlenecks that…

newsletterhibernatejavajpamysql

9 May 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how the default entity sequence changes when migrating from Hibernate 5 to Hibernate 6. Domain Model Let’s assume we have a Post parent entity that has a one-to-many bidirectional association with the PostComment child entity. The Post parent entity looks like this: And the PostComment looks as follows: Notice that both…

hibernatesequencegeneratordatabase sequence

3 May 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article, which explains the bad parts of PostgreSQL. While PostgreSQL is a great open-source database…

newsletterhibernatejavajpamysql

4 Apr 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article, which explains the performance optimizations done by the Quora engineering team to scale their…

newsletterhibernatejavajpamysql

14 Mar 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see how Spring Data query methods are built, when you should use them, and especially when you should avoid them. I decided to write this article after answering this StackOverflow question, which depicts an 87-character-long Spring Data query method. TL;DR, Don’t write query methods that cannot even fit on the screen. Spring…

springhibernatequeryquery methodspring data

1 Mar 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article that explains why an SQL Server query executed by an application can have a…

newsletterhibernatejavajpamysql

16 Feb 2023

vladmihalcea 1 min read

Introduction In this article, I will show you the best way to generate a TSID entity identifier with JPA and Hibernate. Prior to continuing, if you are not familiar with the advantages of using compact Time-Sorted Identifiers, like TSID, check out this article first. Hypersistence Utils As promised, the Hypersistence Utils OSS library keeps on evolving, adding more and more…

hibernatehypersistence utilsidentifierjpatsid

1 Feb 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article that not only explains how B+Tree indexes work in PostgreSQL, but it provides an…

newsletterhibernatejavajpamysql

24 Jan 2023

vladmihalcea 1 min read

Introduction In this article, we are going to see that scaling the data access layer of a Spring application can be done very easily with a YugabyteDB cluster. As I explained in this article, YugabyteDB is an open-source distributed SQL database that offers all the benefits of a typical relational database (e.g., SQL, strong consistency, ACID transactions) with the advantages…

hibernateclusterscalabilityscalingspring

5 Jan 2023

vladmihalcea 1 min read

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this edition is this article about 10 common PostgreSQL mistakes and how you can avoid them. If you want…

newsletterhibernatejavajpamysql

27 Dec 2022

vladmihalcea 1 min read

Introduction In this article, I explain why the Hibernate Types became Hypersistence Utils, and how you can migrate your old dependency to Hypersistence Utils 3.0. Hibernate Types The Hibernate Types project was first created in September 2017 with the goal of offering various Hibernate Types that were not supported natively, like support for JSON or ARRAY column types. Over the…

hibernatespringhibernate-typeshypersistencehypersistence utils

15 Dec 2022

vladmihalcea 1 min read

Introduction In this article, we are going to see how we can configure Spring Data to register several Hibernate Entity Listeners that can intercept entity state modifications. As I explained in this article, JPA also offers an event listening mechanism that you can configure via the @EntityListeners, @PostPersist or @PostUpdate, or PostRemove annotations. However, the JPA solution is way too…

hibernatespring

8 Feb 2022

lukaseder 1 min read

I’ve recently stumbled upon this interesting Stack Overflow question about Hibernate’s popular MultipleBagFetchException. The question is super popular, and the answers are plenty. The various limitations are discussed throughout the question, it all boils down to a simple fact: Joins are the wrong tool to nest collections. Given a schema like the Sakila database: There … Continue reading No More…

jooq-in-usesqlcartesian productseager loadinghibernate

11 Jan 2022

lukaseder 1 min read

N+1 queries are a popular problem in many applications that run SQL queries. The problem can be described easily as follows: 1 query fetching a parent value is run N queries fetching each individual child values are run This problem isn’t limited to SQL, it can happen with any poorly designed API that does not … Continue reading Using jOOQ’s…

jooq-in-usediagnosticsdiagnosticsconnectiondiagnosticslistenerhibernate

26 Aug 2021

lukaseder 1 min read

If your legacy JPA application is using occasional native queries or Hibernate @Formula or Spring Data @Query annotation with vendor specific native SQL embedded in it, you can use jOOQ’s parsing connection and parsing data source to translate between dialects, without having to go all in on your jOOQ adoption – though I think it’s … Continue reading Using jOOQ…

jooq-in-useeclipselinkhibernatejavajooq

24 Aug 2017

lukaseder 1 min read

One of the cooler hidden features in jOOQ is the JPADatabase, which allows for reverse engineering a pre-existing set of JPA-annotated entities to generate jOOQ code. For instance, you could write these entities here: (Just a simple example. Let’s not discuss the caveats of @ManyToMany mapping). For more info, the full example can be found … Continue reading jOOQ 3.10…

javajooq-in-usejpaattributeconverterhibernate

28 Jun 2017

lukaseder 1 min read

In this article, I will establish how the SQL language and its implementations distinguish between changed values and modified values, where a changed value is a value that has been “touched”, but not necessarily modified, i.e. the value might be the same before and after the change. Many ORMs, unfortunately, either update all of a … Continue reading ORMs Should…

javasqlactive recordhibernatejooq

30 May 2017

lukaseder 1 min read

Users of jOOQ, PL/SQL, T-SQL are spoiled as they hardly ever need to worry about bind values. Consider the following statements: Using jOOQ The method parameters firstName and lastName will be automatically mapped to bind values in the generated SQL statement. Here’s the debug log output when running the above, where the first statement is … Continue reading When to…

sqlbind parametersbind variableshibernateinline values

2 Nov 2016

lukaseder 1 min read

I’m very happy to have another interesting blog post by Vlad Mihalcea on the jOOQ blog, this time about his Open Source library flexypool. Read his previous jOOQ Tuesdays post on Hibernate here. Vlad is a Hibernate developer advocate and he’s the author of the popular book High Performance Java Persistence, and he knows 1-2 … Continue reading Applying Queueing…

javasqlerlangflexypoolhibernate

21 Jun 2016

lukaseder 1 min read

Welcome to the jOOQ Tuesdays series. In this series, we’ll publish an article on the third Tuesday every other month where we interview someone we find exciting in our industry from a jOOQ perspective. This includes people who work with SQL, Java, Open Source, and a variety of other related topics. I’m very excited to … Continue reading jOOQ Tuesdays:…

javajooq-tuesdayssqlhibernatehibernate performance

24 Sept 2015

lukaseder 1 min read

We’re very happy to announce a guest post by Marco Behler, who has been blogging about jOOQ in the past. Marco started out in programming (reverse-engineering, actually) and now mainly programmes on the JVM in his day-to-day work. He also always had a sweet tooth for strategy and marketing. Marco Behler GmbH is the result … Continue reading It is…

javasqlconnection poolinghibernatejdbc

14 Apr 2015

lukaseder 1 min read

Welcome to the jOOQ Tuesdays series. In this series, we’ll publish an article on the third Tuesday every other month where we interview someone we find exciting in our industry from a jOOQ perspective. This includes people who work with SQL, Java, Open Source, and a variety of other related topics. We have the pleasure … Continue reading jOOQ Tuesdays:…

jooq-tuesdayshibernatejavajooq tuesdaysjpa

24 Mar 2015

lukaseder 1 min read

Hibernate has become a de-facto standard in the Java ecosystem, and after the fact, also an actual JavaEE standard implementation if standards matter to you, and if you put the JCP on the same level with ISO, ANSI, IEEE, etc. This article does not intended to discuss standards, but visions. Hibernate shares JPA’s vision of … Continue reading jOOQ vs.…

javasqlhibernatejooqorm

29 Dec 2014

lukaseder 1 min read

We’ve recently published an article about how to bind the Oracle DATE type correctly in SQL / JDBC, and jOOQ. This article got a bit of traction on reddit with an interesting remark by Vlad Mihalcea, who is frequently blogging about Hibernate, JPA, transaction management and connection pooling on his blog. Vlad pointed out that … Continue reading Leaky Abstractions,…

javasqlhibernateinternal functionjpa

8 Sept 2014

lukaseder 1 min read

This recent question on Stack Overflow made me think. Why does jOOQ suggest to put generated code under “/target” and not under “/src”? … and I’m about to give you the final answer to “Where to Put Generated Code?” This isn’t only about jOOQ Even if you’re not using jOOQ, or if you’re using jOOQ … Continue reading Look no…

javagenerated codegenerated source codehibernatejooq

26 Jun 2014

lukaseder 1 min read

Writing tests that use an actual database is hard. Period. Now that this has been established, let’s have a look at a blog post by Marco Behler, in which he elaborates on various options when testing database code, with respect to transactionality. Testing database transactions is even harder than just testing database code. Marco lists … Continue reading Stop Unit…

javasqldatabaseshibernateintegration testing

7 Jan 2014

Schakko 1 min read

Recently I struggled upon the same problem, this guy described. Our Oracle database instance contains multiple schematics with almost the same structure. Every developer has it’s own schema for unit and integration tests. On application startup the Hibernate schema validator calls the DatabaseMetaData.getTables() for every linked entity. The method returns the first […] The post Hibernate uses wrong schema during…

application serverdatabasesdatabasehibernatejava