Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOOQ and Spring

Has anyone tried using JOOQ with the Spring framework or am I breaking new ground?

http://www.jooq.org

like image 627
donaldh Avatar asked Dec 17 '10 20:12

donaldh


People also ask

What is spring boot jOOQ?

Java Object Oriented Querying (jOOQ) is a popular product from Data Geekery which generates Java code from your database, and lets you build type safe SQL queries through its fluent API. Both the commercial and open source editions can be used with Spring Boot.

What is the difference between jOOQ and JPA?

JOOQ gives you full control because you can read and write the actual query in your code but with type safety. JPA embraces the OO model and this simply does not match the way a database works in all cases, which could result in unexpected queries such as N+1 because you put the wrong annotation on a field.

Is jOOQ an ORM?

jOOQ is an ORM-alternative that is relational model centric rather than domain model centric like most ORMs.

What is jOOQ DSL?

jOOQ is a DSL (domain-specific language), which mimicks both standard and vendor-specific SQL syntax in a Java API. The idea behind this API is easy to understand: Being an internal DSL, the Java compiler can verify your SQL queries for syntactic correctness (e.g. correct order of SQL keywords)


2 Answers

Yes, many people have (by now). And the jOOQ manual includes a tutorial about how to get started using jOOQ, Spring, Spring-TX and BoneCP:

  • http://www.jooq.org/doc/latest/manual/getting-started/tutorials/jooq-with-spring/

There is also a very good tutorial by Petri Kainulainen, explaining every step to set up a project, here:

  • Using jOOQ with Spring: Configuration
  • Using jOOQ with Spring: Code Generation
  • Using jOOQ with Spring: CRUD
  • Using jOOQ with Spring: Sorting and Pagination

Here's a blog post about how to use jOOQ with Spring Boot, especially useful when you need the commercial distributions of jOOQ:

  • https://blog.jooq.org/2019/06/26/how-to-use-jooqs-commercial-distributions-with-spring-boot/
like image 56
Lukas Eder Avatar answered Sep 25 '22 13:09

Lukas Eder


I was looking to use jOOQ as an builder library for providing queries to Spring's JdbcTemplate and related classes. Unfortunately, jOOQ appears to combine two concepts into the same set of classes: SQL generation and query execution. In my case, I want the former but want to let Spring handle the latter. It does work, though. For example, you can do something like this (using jOOQ 2.x API):

Factory create = new Factory(null, SQLDialect.ORACLE); getJdbcTemplate().query(     create.select(create.field(ID_COL),                   create.field(VALUE_COL))         .from(FOO_TABLE)         .where(create.field(ID_COL).equals("ignored"))         .getSQL(),     myRowMapper,     id); 
like image 20
David Avatar answered Sep 21 '22 13:09

David