The best way to fetch multiple entities by id using JPA and Hibernate

Introduction In this article, we are going to see how we can load multiple entities by id at once when using JPA and Hibernate. Loading multiple entities by their identifier is a very common requirement when using JPA and Hibernate. Hence, we are going to see how we can optimize the underlying SQL query execution. Domain Model For the following examples, we are going to use the following Book entity: Now, let’s consider we have added several Book entities into our database: Notice how nicely we can build the JPA…

Read More

How to map SQL Server JSON columns using JPA and Hibernate

Introduction In this article, we are going to see how easy it is to map an SQL Server JSON column when using the Hibernate Types project. Not only that the hibernate-types project supports JSON column types for PostgreSQL and MySQL and Oracle, but, as you will see in this article, the JsonStringType works just fine when using Microsoft SQL Server. SQL Server JSON storage When using SQL Server, you can use the NVARCHAR column type to persist JSON objects. The advantage of storing JSON in an NVARCHAR column is that…

Read More
java 

Top 5 Courses to learn Hibernate and JPA in 2019

Hibernate is one of the essential frameworks for Java and Java EE or JEE programmers, especially if you are working on the server side of a Java Web development project. It's an ORM tool or a framework which allows you to deal with only objects while Hibernate takes care of your data on your behalf. For example, instead of writing classes with SQL to load, save, and update data using the DAO design pattern, you can simply use the Hibernate framework in your project. It will allow you to deal…

Read More
java 

Top 5 Spring and Hibernate Training Courses for Java JEE Programmers

Spring and Hibernate are two of the hottest and most in-demand web frameworks in Java world and also two of the most essential skill for any Java programmer to get a Job in web development space. The Spring framework is in around from 2004 and established itself as the leading framework to develop Java applications both in core Java and web development area. The Spring framework comes with a lot of modules to support a different kind of developments e.g Spring Security to address the security requirements of most web…

Read More

Mapping PostgreSQL Interval to Java Duration with Hibernate

Introduction In this article, we are going to see how to map the PostgreSQL interval column type to a Java Duration object using Hibernate and the hibernate-types project. Another very useful feature introduced by the hibernate-types project is that all types extending the ImmutableType can now be treated as standard org.hibernate.type.Type, therefore enabling a much better Hibernate Core API integration. Domain Model Assuming we have the following book database table that defines a presale_period column of the interval type. We can map the book table to a Book JPA entity…

Read More

How to map multiple JPA entities to one database table with Hibernate

Introduction In this article, we are going to see how we can map multiple JPA entities to one table with Hibernate. Using multiple entities can speed up both read and write operations. This question has been a recurring theme on StackOverflow, so I decided to explain the advantages of mapping multiple JPA entities to the same database table. Domain Model Let’s assume we have a book database table that looks as follows: Notice that the properties column is of the jsonb type. Therefore, the properties column value is as large…

Read More
MatLab 

DevNation Live: Quarkus – Hibernate with Panache

DevNation Live tech talks are hosted by the Red Hat technologists who create our products. These sessions include real solutions and code and sample projects to help you get started. In this talk, you’ll learn about Hibernate and Quarkus from Emmanuel Bernard, Distinguished Engineer and Chief Architect Data at Red Hat. Not only does Quarkus boot extremely fast and with low memory footprint, but it also brings supersonic development time to developers with live reload, fast tests, and streamlined code for 80% of common usages. One of the massively streamlined…

Read More

Fluent Entities with Hibernate and JPA

The post Fluent Entities with Hibernate and JPA appeared first on Thoughts on Java. Fluent interfaces are a popular API design pattern in the Java world. The goal of the pattern is to create APIs that are very easy to read, and that define something similar to a domain-specific language. To achieve that, the API heavily relies on method chaining so that the code that uses the API flows and almost reads like prose. A basic example of a fluent API might look like this: Book b = new Book()…

Read More
java 

Hibernate Tip: Join Unassociated Entities in Criteria Query

The post Hibernate Tip: Join Unassociated Entities in Criteria Query appeared first on Thoughts on Java. Hibernate Tips is a series of posts in which I describe a quick and easy solution for common Hibernate questions. If you have a question for a future Hibernate Tip, please post a comment below. Question: In a previous article, I showed how to join to unassociated entities using JPQL and Hibernate’s proprietary query features. Since I published that post, I get asked how to do the same in a CriteriaQuery. So, let’s take…

Read More

Enum Mappings with Hibernate – The Complete Guide

The post Enum Mappings with Hibernate – The Complete Guide appeared first on Thoughts on Java. Most developers use enums in their domain models. You can easily map them with Hibernate. They provide a strongly typed way to model an attribute that has one out of a list of defined values. The format of a book is a typical example of such an enum. Supported values could be hardcover, paperback, and ebook. With JPA and Hibernate, you can map enums in different ways. You can: use the standard mappings to…

Read More