I have had my share of performance problems caused by ORM tools, and if you have used them, you must know what I am talking about. Two most common performance problems caused by ORM tools are:
- The N + 1 selects problem
- Selecting partial objects is hard which ensures that index-only scans are never done.
At some point I decided to eliminate some of these problems by making one simple decision: I stopped using an ORM tool for read-only operations. When I was looking for alternative way to implement read-only queries, I ran into jOOQ.
jOOQ is a library which helps you to get back in control of your SQL. It can generate code from your database and lets you build typesafe database queries by using its fluent API.
jOOQ helps you to solve the performance problems caused by ORM tools because you (and not the ORM tool) decide what kind of SQL queries your applications executes against its database.
You can of course solve these problems by using JDBC but this creates few new problems:
- Writing SQL queries manually is time consuming.
- Writing SQL queries manually is error prone because errors are detected at run time.
- Writing SQL queries manually creates a vendor lock-in.
jOOQ solves every one of these problems!
Are you excited? I though so.
Introducing: Using jOOQ With Spring
This five part tutorial will help you get started with jOOQ and it consists of the following blog posts:
- Using jOOQ With Spring: Configuration describes how you can get the required dependencies with Maven, transform jOOQ specific exceptions to Spring DataAccessExceptions, and configure the persistence layer of your application by using Java configuration.
- Using jOOQ With Spring: Code Generation describes how you can generate the required jOOQ query classes from your database by using the jOOQ-codegen Maven plugin.
- Using jOOQ With Spring: CRUD describes how you can add CRUD operations to a jOOQ repository.
- Using jOOQ With Spring: Sorting and Pagination describes how you can implement a simple search function which supports both sorting and pagination.
- Using jOOQ with Spring: Best of Both Worlds (TBD)
This section showcases useful material created by other developers. If you have written a blog post or recorded a video about jOOQ, and want to include it to this section, ping me on Twitter and I will check it out. If I think that it is useful, I will add it to this section.
- jOOQ – Type safe DB querying on JCG Academy. This FREE course has a five star rating, and it is written by Lukas Eder (The creator of jOOQ). Check it out!