Featured Image with Sidebar

Coffee with Thorben 2020-02-12 – JPQL vs Criteria vs Native Queries

By Thorben Janssen


Join the chat on YouTube.

JPQL vs. Criteria vs. Native Queries

With JPQL and native SQL queries, Hibernate supports 2 query languages that you can use to search data in your database. In addition to that, there is also JPA’s Criteria API that replaced Hibernate’s proprietary Criteria API.

It might seem like there are 3 different ways to do the same thing. But that’s not the case. Each type of query has specific strengths, limitations, and weaknesses, making it a great fit for some but not all use cases.

In today’s stream, we will discuss the different types of queries you can use with Hibernate and when you should prefer them.

If you want to dive deeper into the different types of queries supported by Hibernate, you should read the following articles:

Live Online Workshops

If you enjoyed the live stream, you will love my live online workshops. Find out more at thorben-janssen.com/workshops.

Question of the Week

When you use JPQL’s path operator “.”, you can navigate a to-one association without specifying a JOIN expression in your FROM clause. But that doesn’t mean that Hibernate doesn’t need to generate such an expression when it generates the SQL statement. This often causes unexpected results:

JPA query to concat null field

This week’s tutorials

Blog

Do you know Hibernate’s query spaces? They are used to decide when entities need to be flushed and which parts of the cache need to get invalidate when performing a bulk update. Most of the time, Hibernate manages its query spaces automatically but there are some situations in which it needs some help.

I explained all of that in great detail in this week’s post: Hibernate Query Spaces – Optimizing Flush and Cache Operations.

YouTube

One of the big strengths of the Spring ecosystem and especially of Spring Boot is the integration of popular libraries. The integrations of Flyway and Liquibase are good examples of that. Both libraries are the industry standard for version based database migrations, and Spring Boot makes using them incredibly simple.

I show you how to integrate these 2 popular libraries into your application in this week’s video:

About the author

Thorben is an independent consultant, international speaker, and trainer specialized in solving Java persistence problems with JPA and Hibernate.
He is also the author of Amazon’s bestselling book Hibernate Tips - More than 70 solutions to common Hibernate problems.

Tools

Books and Courses

Coaching and Consulting

Leave a Reply

Your email address will not be published. Required fields are marked

This site uses Akismet to reduce spam. Learn how your comment data is processed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}