How to execute SQL functions with multiple parameters in a JPQL query with Hibernate
Introduction In this article, we are going to see how you can execute SQL functions with multiple parameters in JPQL queries with Hibernate. I recently stumbled on this requirement while answering this StackOverflow question, which is a never-ending source of inspiration for articles on my blog.
How to merge entity collections with JPA and Hibernate
Introduction In this article, you are going to learn why overwriting entity collections is an anti-pattern and how you can merge collections both effectively and efficiently with JPA and Hibernate. The reason I decided to write this article is that I’ve been this question asked over and over and over again.
How to map the Java YearMonth type with JPA and Hibernate
Introduction In this article, we are going to see how you can map a java.time.YearMonth with both JPA and Hibernate. As I explained in this article, JPA 2.2 supports the following Date/Time types introduced in Java 8: java.time.LocalDate java.time.LocalTime java.time.LocalDateTime java.time.OffsetTime java.time.OffsetDateTime Apart from supporting those, Hibernate supports also: java.time.Duration java.time.Instant java.time.ZonedDateTime However, neither JPA nor Hibernate support the java.time.YearMonth out-of-the-box. As you will see, adding support for java.time.YearMonth is really straightforward for both standard JPA or Hibernate.
Query pagination with JPA and Hibernate
Introduction Inspired by this StackOverflow answer I gave recently, I decided it’s time to write an article about query pagination when using JPA and Hibernate. In this article, you are going to see how to use query pagination to restrict the JDBC ResultSet size and avoid fetching more data than necessary.
Spring read-only transaction Hibernate optimization
Introduction In this article, I’m going to explain how the Spring read-only transaction Hibernate optimization works. After taking a look at what the Spring framework does when enabling the readOnly attribute on the @Transactional annotation, I realized that only the Hibernate flush mode is set to FlushType.MANUAL without propagating the read-only flag further to the Hibernate Session. So, in the true spirit of open-source software developer, I decided it’s time to make a change.
Hibernate performance tuning tips
Introduction In this article, I’m going to summarise the most common Hibernate performance tuning tips that can help you speed up your data access layer. While getting started with JPA and Hibernate is fairly easy, if you want to get the most out of your data access layer, it’s very important to understand how the JPA provider works, as well as the configuration properties that can help you optimize application performance.
How to map the PostgreSQL inet type with JPA and Hibernate
Introduction In this article, we are going to see how to map the PostgreSQL inet type with JPA and Hibernate. Traditionally, PostgreSQL has been offering more column types than other relational database systems. And you don’t even have to implement these types I’m presenting here since they are available via the Hypersistence Utils project.
The best way to clone or duplicate an entity with JPA and Hibernate
Introduction Have you ever wondered how to clone an entity with JPA or Hibernate? Recently, I stumbled upon this Hibernate forum question and it reminded me that this was a common requirement when working with JPA and Hibernate. In this article, we are going to see the best way to clone a JPA entity with JPA and Hibernate.
Hibernate database schema multitenancy
Introduction As I explained in this article, multitenancy is an architectural pattern which allows you to isolate customers even if they are using the same hardware or software components. There are multiple ways you can achieve multitenancy, and in this article, we are going to see how you can implement a multitenancy architecture using the database schema as the unit of isolation.
How to fix the Hibernate “No Dialect mapping for JDBC type” issue
Introduction Recently, stumbled on this question on the Hibernate forum, and since I’ve been seeing it before on StackOverflow and bumped into it myself while working with JPA and Hibernate, I decided to turn the answer into an article. Therefore, in this article, you are going to find out how you can fix the “No Dialect mapping for JDBC type” Hibernate issue.