No More MultipleBagFetchException Thanks to Multiset Nested Collections

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 MultipleBagFetchException Thanks to Multiset Nested Collections

Using jOOQ’s DiagnosticsConnection to detect N+1 Queries

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 runN 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 allow … Continue reading Using jOOQ’s DiagnosticsConnection to detect N+1 Queries

Using jOOQ to write vendor agnostic SQL with JPA’s native query or @Formula

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 to write vendor agnostic SQL with JPA’s native query or @Formula

A Frequent Question: Does jOOQ Have a First Level Cache?

One of the more frequent questions people have when switching from JPA to jOOQ is how to migrate from using JPA's first level cache? https://twitter.com/dmitrygusev/status/1034208767406043136 There are two important things to notice here: jOOQ is mainly used for what JPA folks call "projections" If you're using only JPA in your application, you may have gotten … Continue reading A Frequent Question: Does jOOQ Have a First Level Cache?

Truth First, or Why You Should Mostly Implement Database First Designs

In this much overdue article, I will explain why I think that in almost all cases, you should implement a "database first" design in your application's data models, rather than a "Java first" design (or whatever your client language is), the latter approach leading to a long road of pain and suffering, once your project … Continue reading Truth First, or Why You Should Mostly Implement Database First Designs

jOOQ 3.10 Supports JPA AttributeConverter

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: @Entity public class Actor { @Id @GeneratedValue(strategy = IDENTITY) public Integer actorId; @Column public String firstName; @Column public String lastName; @ManyToMany(fetch … Continue reading jOOQ 3.10 Supports JPA AttributeConverter

ORMs Should Update “Changed” Values, Not Just “Modified” Ones

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 Update “Changed” Values, Not Just “Modified” Ones

When to Use Bind Values, and When to Use Inline Values in SQL

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 public int countActors(String firstName, String lastName) { return ctx.selectCount() .from(ACTOR) .where(ACTOR.FIRST_NAME.eq(firstName)) .and(ACTOR.LAST_NAME.eq(lastName)) .fetchOneInto(int.class); ); } The method parameters firstName and lastName will be automatically mapped to bind values in the generated SQL … Continue reading When to Use Bind Values, and When to Use Inline Values in SQL

Applying Queueing Theory to Dynamic Connection Pool Sizing with FlexyPool

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 Theory to Dynamic Connection Pool Sizing with FlexyPool

jOOQ Tuesdays: Thorben Janssen Shares his Hibernate Performance Secrets

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: Thorben Janssen Shares his Hibernate Performance Secrets