Questions tagged [jooq]

jOOQ stands for JOOQ Object Oriented Querying. jOOQ effectively combines complex SQL, typesafety, source code generation, active records, stored procedures, advanced data types, and Java in a fluent, intuitive DSL.

What's jOOQ?

jOOQ stands for JOOQ Object Oriented Querying. It combines these essential features:

  • Code Generation:

    jOOQ generates a simple Java representation of your database schema. Every table, view, stored procedure, enum, and UDT is a class.

  • Active records:

    jOOQ implements an easy-to-use active record pattern. It is not an OR-mapper, but provides a 1:1 mapping between tables/views and classes, between columns and members.

  • Typesafe SQL:

    jOOQ allows for writing compile-time typesafe querying using its built-in DSL.

  • SQL standard:

    jOOQ supports all standard SQL language features including the more complex UNIONs, nested SELECTs, joins, and aliasing.

  • Vendor-specific feature support:

    jOOQ encourages the use of vendor-specific extensions such as stored procedures, UDTs, ARRAYs, and many more.

How does jOOQ help you?

  • Your database always comes FIRST! That's where the real schema is, not in Java code or some XML mapping file with syntax you're not familiar with.
  • You keep your code DRY.
  • You won't suffer from the Object-Relational impedance mismatch.
  • You won't have syntax errors in your query.
  • You won't forget to bind variables correctly. No SQL injection, either.
  • You don't need to know your database schema by heart when you develop. The schema is generated in Java. You can use auto-completion in your IDE!
  • You don't need to create value objects for your data. Use the generated artifacts instead.
  • You have automatic type mapping between SQL data types and Java types.
  • You change something in the database? Your Java code won't compile. You don't need to wait until runtime to notice.
  • You can forget about JDBC (especially useful when dealing with UDTs, ARRAYs and stored procedures).
  • You can port your SQL to a new database. jOOQ will generate SQL that works on any database.

When to use jOOQ

jOOQ is not an OR-mapper. jOOQ is low-level relational persistence abstraction. In principle, you could even write an OR-mapper on top of jOOQ. If you're aware of this, you can benefit most from jOOQ...

  • When you love your RDBMS of choice, including all its vendor-specific features.
  • When you love control over your code.
  • When you love the relational data model (read this interesting article).
  • When you love SQL.
  • When you love stored procedures.

See the examples for yourself. You'll be convinced in no time! :-)

When not to use jOOQ

On the other hand, many people like the ease of use of Hibernate or other products, when it comes to simply persisting any domain model in any database. You should not use jOOQ...

  • When you don't care about your database (or "persistence" as it is called).
  • When you don't really need SQL.
  • When you want to map your object-oriented domain model to a database and not vice versa.
  • When you need to write DDL statements. jOOQ only supports DML statements.

What databases are supported

Every RDMBS out there has its own little specialties. We consider those specialties as much as possible, while trying to standardise the behaviour in jOOQ. In order to increase the quality of jOOQ, we run unit tests for syntax and variable binding verification, as well as integration tests for any of these databases:

  • Access
  • Aurora for MySQL
  • Aurora for PostgreSQL
  • Azure SQL Database
  • Azure SQL Data Warehouse
  • CUBRID
  • DB2
  • Derby
  • Firebird
  • H2
  • HSQLDB
  • Informix
  • Ingres
  • MariaDB
  • MySQL
  • Oracle
  • PostgreSQL
  • Redshift
  • SQLite
  • SQL Server
  • Sybase Adaptive Server Enterprise
  • Sybase SQL Anywhere
  • Teradata
  • Vertica

Similar products

When you consider jOOQ for your project, you might also have considered any of these similar products:

  • Querydsl: Focusing on the DSL and abstracting "backend integrations", such as SQL, JPA, collections, etc. The "complete LINQ of Java".
  • JaQu: Writing SQL statements using actual Java expressions

And with database tools, such as

  • ActiveJDBC: A simple mapping tool implementing ActiveRecords in a Ruby-like way

And with OR-mapping tools, such as

  • Hibernate: The mother of all inspiration to Java persistence
  • JPA: The Java EE standard

License

jOOQ is dual-licensed under the Apache Software License 2.0 and commercially licensed.

2566 questions
1
vote
1 answer

Java JOOQ multiple tables query

I have a problem. I have the following query: SELECT Agents.Owner, Orders.* FROM Orders INNER JOIN Agents ON Agents.id = Orders.agentid WHERE Agents.botstate = 'Active' AND Orders.state = 'Active' AND( Orders.status =…
A. Vreeswijk
  • 822
  • 1
  • 19
  • 57
1
vote
1 answer

Spring Boot vs JOOQ vs Unix socket

I have Spring boot app with JOOQ for working with PostrgesDB. This app must be running on Google cloud. If I deploy this as AppEngine Flex all works without problem. Now I need deploy and run this app into the google run. Way for connect Cloud Run…
Jan Tomek
  • 11
  • 2
1
vote
1 answer

How to only update some fields, when using jOOQ's batch loader with onDuplicateKeyUpdate?

Is it possible to only update some fields when a duplicate is found, using jOOQ's batchAll() loader? Similar to how onDublicateKeyUpdate() can be used for single records:…
Christoffer Karlsson
  • 4,539
  • 3
  • 23
  • 36
1
vote
1 answer

JOOQ: update two tables with one2one relation

I have 2 tables with 1:(0 or 1) relations for example: table1 - students id last_name first_name 1 Hart John table2 - student_address id student_id address is_married 1 1 something true not every student has an address (for…
1
vote
1 answer

JOOQ - Join on condition or not exit

I have the following query: Map> resultMap = dslContext .select() .from(BUSINESS.leftJoin(BUSINESS_ADDRESS).on(BUSINESS.ID.eq(BUSINESS_ADDRESS.BUSINESS_ID))) …
Mankind1023
  • 7,198
  • 16
  • 56
  • 86
1
vote
1 answer

How to add a semi colon ; automatically to each generated sql statement using jOOQ

I'm trying to add a semi colon ; to every jOOQ generated sql statement as I'm writing multiple DDL and insert statement to an output file. I found a similar question here suggesting using an ExecuteListener here…
Marcel Overdijk
  • 11,041
  • 17
  • 71
  • 110
1
vote
1 answer

Using jOOQ as schema generator (plain sql as output)

I'm trying to use jOOQ as a schema generator to generate DDL statements, and later to generate SQL insert statements. The underlying data is coming from static CSV files and I basically want to write a static SQL script which includes statements to…
Marcel Overdijk
  • 11,041
  • 17
  • 71
  • 110
1
vote
1 answer

Incorrect sql generated by jooq on rare occasions

I have a spring cloud gateway application saving authentication data to db. Application runs in kubernetes. I have too different cases, sometimes I have json data to save and other times json data is null. Code to save this data looks like this: …
1
vote
1 answer

Is it possible to implement MySQL JSON_MERGE_PATCH with JOOQ data binding?

Question: In my MySQL database, I have an info column of JSON type: info json DEFAULT NULL, I wrote a simple converter as follows and registered it with the code generator: class JsonMapConverter : AbstractConverter
1
vote
1 answer

JOOQ - Join table using string name

I have an app in the process of switching from jooq to jdbc, I created a table using jdbc but I need to edit some jooq queries to join it in, problem is that the auto generated jooq tables class does not recognize it, so is there a way to reference…
Mankind1023
  • 7,198
  • 16
  • 56
  • 86
1
vote
1 answer

Using Postgres (and AWS Redshift) DB Link with JOOQ

We are trying to establish a DB link between Postgres and AWS Redshift DB (which isn't a problem) but we are using JOOQ to construct DB Query for the same. What is working? We are able to write JOIN SQL queries for the data we want to fetch…
Shubham A.
  • 2,446
  • 4
  • 36
  • 68
1
vote
1 answer

How do you convert the SQL `to_date(date) - INTERVAL '1 MONTH'` to JOOQ's DSL API?

JOOQ's Date docs contain the usual date functions (to_date, dateadd, ect..). However, I couldn't find any docs explaining how to use SQL's INTERVAL type to perform date math. Can this SQL be represented in JOOQ or is my only option to dip down into…
1
vote
1 answer

Jooq codegen classes for ref-cursor on oracle12 and oracle19

I have plsql code in package context: type t_demand_for_excel_upload is record ( bsns_oper_name t_string, demand_date date, demand_hour integer, demand_value number ); type t_cur_demands_for_excel_upload is ref cursor return…
1
vote
1 answer

How to orderby using alias in jooq

In the example below, how can I orderBy "amount" (which is an alias created by me using a subquery) in jooq? I cannot understand how to do it reading the documentation. return context .select( NAME, …
Mavek
  • 63
  • 1
  • 6
1
vote
0 answers

Generating MySQL INSERT/ DELETE multiple rows statement

I am a new beginner in JOOQ and I have a curious question. I need to generate insert statements and dump the records to a file in the below format: INSERT INTO table_name (column_list) VALUES (value_list_1), (value_list_2), ... …
1 2 3
99
100