Has anyone tried using JOOQ with the Spring framework or am I breaking new ground?
http://www.jooq.org
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.
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.
jOOQ is an ORM-alternative that is relational model centric rather than domain model centric like most ORMs.
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)
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:
There is also a very good tutorial by Petri Kainulainen, explaining every step to set up a project, here:
Here's a blog post about how to use jOOQ with Spring Boot, especially useful when you need the commercial distributions of jOOQ:
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With