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

PrivilegedActionException in quarkus when using JOOQ

First up; the code works. I'm getting an exception in my log but no actual error actually occurs. The correct output gets sent to the client, the app keeps running, as far as I can tell everything is fine. Yet I have an error. I'm using Quarkus and…
jurgen
  • 325
  • 1
  • 11
1
vote
2 answers

ERROR: recursive query "t" column 3 has type character varying(255) in non-recursive term but type character varying overall

I have this table. CREATE TABLE directory ( id INT NOT NULL, parent_id INT, label character varying(255), CONSTRAINT pk_directory PRIMARY KEY (id), CONSTRAINT fk_directory FOREIGN KEY (parent_id) REFERENCES…
hebawa2570
  • 31
  • 1
1
vote
0 answers

Jooq selectFrom is not returning all the records

When I run the following query on a database function in postgresql select * from public.getData() *** getData() is the db function This returns record s…
1
vote
1 answer

How to pass current record as parameter to a routine?

I am attempting to invoke a PL/SQL function via jOOQ using the routines. The function is as follows: CREATE OR REPLACE FUNCTION myschema.default_sort(rec myschema.mytable) RETURNS text LANGUAGE SQL IMMUTABLE AS $$ SELECT …
Eric H
  • 1,323
  • 3
  • 14
  • 29
1
vote
1 answer

How to generate source code for psql views

For a view created using psql, I want to generate source code. The below config conveyed in jooq didn’t work. sources = true sourcesOnViews = true Can you please let me know your thoughts.
ramya
  • 11
  • 1
1
vote
1 answer

jOOQ code generation fails on triggers - how to skip them?

In my application I use Flyway to migrate the database. I have a SQL file containing the database structure which includes some CREATE TRIGGER statements. jOOQ code generation fails because it uses H2 which does not support triggers. What is the…
McPringle
  • 1,939
  • 2
  • 16
  • 19
1
vote
1 answer

Jooq mock fetchInto

As i found it is possible to mock result of jooq request . But is it possible to mock fetchInto function for example? I have this code val addressSaved = dsl.selectFrom(address) .where(address.CITY.eq(city)) …
Dimitry
  • 99
  • 6
1
vote
2 answers

Can't get my SpeakerRecord entity when joining with jOOQ

I have three tables: event, speaker, event_speaker Events and speakers have an n:m relationship managed by the "event_speaker" table. I used the jOOQ maven codegen to generate files like "EventRecord" and "SpeakerRecord". In my application I want to…
McPringle
  • 1,939
  • 2
  • 16
  • 19
1
vote
1 answer

Using Postgres VALUES function in an IN clause in JOOQ

I have to perform a query with a huge IN clause (about 1000 values). For example, in SQL it would look like WHERE "entity"."page" IN (1, 2, 3, 4, 5,...) In Postgres it seems to be a lot faster when you use the VALUES function in the IN clause like…
jch-me
  • 13
  • 3
1
vote
1 answer

Explicitly casting enum in case query

I am building a Postgres query using jOOQ (the query isn't sent to the DB using jOOQ though, it's used for creating the queries that are used by vertx). The query incorporates a piece with a "case": ... set "state" = case when…
atarno
  • 329
  • 1
  • 3
  • 14
1
vote
1 answer

Boolean fields in JOOQ classes not serialized and deserialized consistenly by Jackson/RestEasy

I have a Java EE project that uses JOOQ to auto generate records using Kotin. One such record is: @Suppress("UNCHECKED_CAST") open class EmailAddressRecord() : UpdatableRecordImpl(EmailAddress.EMAIL_ADDRESS), Record5
assylias
  • 321,522
  • 82
  • 660
  • 783
1
vote
1 answer

Can jOOQ support composite primary keys if auto-increment field isn't the first one

I'm using jOOQ (3.14.11) to manage a table defined (in H2 or MYSQL) as: CREATE TABLE example_one ( group_id VARCHAR(36) NOT NULL, pawn_id INT UNSIGNED AUTO_INCREMENT NOT NULL, some_unimportant_attribute INT UNSIGNED DEFAULT 0 NOT…
goolie
  • 145
  • 1
  • 7
1
vote
1 answer

Generate Dynamic Query using JOOQ

I want to generate a SQL query where tables name is stored in the tables array. and the corresponding columns name stored in a 2-D array. example:- Tables array [T1,T2,T3] Columns array [ [C1,C2], // T1 columns [C1,C2], // T2 columns …
pranay
  • 35
  • 3
1
vote
1 answer

Select as boolean using PostgreSQL 'crypt()' function

I'm trying to replicate the following SQL query using jOOQ, and I'm running into some errors. I'm want to see if a direct replacement is possible, before re-working the query if required, so just looking for some advice. SELECT …
zodac
  • 285
  • 10
  • 26
1
vote
1 answer

Use UNNEST inside JOOQ's select

I have the SQL like: select * from some_table where (select array(select unnest(first_array_field) except select unnest(second_array_field))) @> '{some_value}'; This is my try to write the where condition for that query in a JOOQ way: private…
fee1good
  • 119
  • 1
  • 1
  • 7