Introduction The Hibernate forum is a never-ending source of inspiration when it comes to solving real-life problems you might bump into when developing an enterprise application. For instance, this post asks about a JPQL query which should fetch a given parent entity when all its child entities match the given filtering criteria.
Introduction When executing an entity query (e.g. JPQL, HQL or Criteria API), you can use any SQL function without having to register it as long as the function is passed directly to the WHERE clause of the underlying SQL statement. However, if the SQL function is used in the SELECT clause, and Hibernate has not registered the SQL function (be it a database-specific or user-defined function), you will have to register the function prior to using it in an entity query. In this article, you are going to learn various ways to… Read More
Introduction Every JPQL query must be compiled prior to being executed, and, because this process might be resource intensive, Hibernate provides a QueryPlanCache for this purpose. For entity queries, the query String representation is parsed into an AST (Abstract Syntax Tree). For native queries, the parsing phase cannot compile the query, so it only extracts information about the named parameters and query return type.
Introduction While doing my High-Performance Java Persistence training, I realized that not all developers are familiar with the getReference method of the JPA EntityManager and most of them use find almost exclusively. In this article, we are going to see the difference between the find and getReference method so that it’s clear when to apply them depending on the underlying use case.
Introduction Traditionally, both MySQL and MariaDB relied on AUTO_INCREMENT columns to generate an IDENTITY Primary Key. Although IDENTITY columns are very efficient in generating the Primary Key value, when it comes to using JPA and Hibernate, the IDENTITY generator prevents us from using JDBC batch inserts. To automatically enroll multiple INSERT, UPDATE or DELETE statements, Hibernate requires delaying the SQL statement until the Persistence Context is flushed. This works very well for the SEQUENCE identifier since the entity identifier can be fetched prior to executing the INSERT statement. However, for IDENTITY columns,… Read More
Introduction Recently, I stumbled on the following Twitter thread: This jOOQ feature is indeed really useful since it reduces the number of SQL statements that have to be generated when varying the IN clause parameters dynamically. Starting with Hibernate ORM 5.2.18, it’s now possible to use IN clause parameter padding so that you can improve SQL Statement Caching efficiency. In this article, I’m going to explain how this new mechanism works and why you should definitely consider it when using a relational database system which supports Execution Plan caching.
Introduction While answering this StackOverflow question, I realized that it’s a good idea to summarize how various bidirectional associations should be synchronized when using JPA and Hibernate. Therefore, in this article, you are going to learn how and also why you should always synchronize both sides of an entity relationship, no matter if it’s @OneToMany, @OneToOne or @ManyToMany.
Introduction I recently answered this question on the Hibernate forum, and since it’s a very good one, I decided to turn it into an article. In this post, we will describe how the N+1 query issue is generated when using the second-level Hibernate Query Cache.
Introduction To get the most out of the relational database in use, you need to make sure the data access layer resonates with the underlying database system. In this article, we are going to see what you can do to boost up performance when using PostgreSQL with JPA and Hibernate.