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

SQL row value expression with null failing in where-in query

I am struggling to understand why this where-in query is failing when there are nulls in the row value expression. select * from FOO where ( EPOCH, CURRENCY_CODE, PRICE_PROVIDER_CODE, MARKET_EXTERNAL_ID) in ( (1622736580084, 'USD', 'A',…
Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
1
vote
0 answers

SQL Exception in JOOQ If exists with MSSQL server

I am using JOOQ for dynamically creating/altering table schemas. my code is working fine with postgres but when I use MSSQL Server. I am getting the SQL Syntex exception with MS SQL server but this my code is working fine with the postgres. While…
Dpkbhardwaj
  • 110
  • 6
1
vote
2 answers

Problems to use ParserCLI

I'm try to use Parser CLI, and I dont know how to solve it. Can someone help me? java -cp jooq-3.15.0-SNAPSHOT.jar:reactive-streams-1.0.3.jar \ org.jooq.ParserCLI -T ORACLE \ -s "SELECT substring('abcde', 2, 3)" Exception in thread "main"…
1
vote
1 answer

R2DBC support in Jooq for Reactive applications

Currently I have written my project using spring boot + hikari connection pool, and fetching the result using fetchAsync method. But according to this documentation Reactive fetching, its Blocking JDBC API. Is it possible to encapsulate…
1
vote
1 answer

How to generate pojos using jooq from two data sources in the same spring boot service

I want to generate pojos using jooq from two datasources (Two separate MySQL database hosted on separate AWS RDS) in the same spring boot serivce. How can I do that? I doubt if following can be used here: jooq { DBONE(sourceSets.main) { …
Aishwer Sharma
  • 205
  • 2
  • 17
1
vote
1 answer

JOOQ difference between DSL and DSLContext, when to use DSL instead of a dslContext instance?

When having queries like this, for the inner query, should I use DSL or the dslContext that I have? return dslContext .insertInto(TABLE_FOO) .select( dslContext // vs DSL here .select( ... …
daltonfury42
  • 3,103
  • 2
  • 30
  • 47
1
vote
1 answer

Insert SQL enum with jOOQ in PostgreSQL database

I'm trying to use jOOQ to insert a SQL enum in my database. The database migration is setup with Liquibase like:
PAK
  • 431
  • 4
  • 17
1
vote
1 answer

JOOQ: How to use postgres generate_series and insert into table?

I am trying to write this PostgreSQL query using JOOQ: INSERT INTO my_table (date, from_city, to_city, rate_per_mile) select g.dt::date, 'city1', 'city2', 13.12 from generate_series(current_date, current_date + 364, interval '1 day') as g(dt); I am…
daltonfury42
  • 3,103
  • 2
  • 30
  • 47
1
vote
1 answer

How to map to an existing Hibernate model using jOOQ fetchInto()?

I'm trying to use the jOOQ fetchInto() method to map to an existing Hibernate model Organization (class and its inheritances are below). Organization organization = jooq().select().from(ORGANIZATION).fetchOne().into(Organization.class); The problem…
Bram
  • 37
  • 1
  • 5
1
vote
1 answer

jooq use custom function in order by statement

I'm currently trying to introduce this function https://stackoverflow.com/a/12257917/4375998 into my project, but struggle with the function signature generated by jooq. The generated code has these three signatures public static String…
Tamwyn
  • 312
  • 4
  • 16
1
vote
1 answer

Java For loop with batch SQL

I have a problem. Right now I am using JOOQ to insert arround 100.000 records in my database using the following code: try (Connection conn = DriverManager.getConnection(SqlConn.getURL(), SqlConn.getUSERNAME(), SqlConn.getPASSWORD())) { …
A. Vreeswijk
  • 822
  • 1
  • 19
  • 57
1
vote
1 answer

Group by date using a datetime field with JOOQ

I have a table called delivery and datetime field delivery_time. +--------------------+------------------------------------------+------+-----+-------------------+ | Field | Type | Null | Key |…
Ruchira Nawarathna
  • 1,137
  • 17
  • 30
1
vote
1 answer

Create dynamic primary key constraint with JOOQ

I am using JOOQ(newbie in JOOQ) to create the database at runtime using Rest API in my spring boot project. In one of the case I need to create a table with a composite primary key which can be combination of multiple columns. I am using the below…
Dpkbhardwaj
  • 110
  • 6
1
vote
1 answer

Upsert with "on conflict do update" with partial index in jOOQ

I have a partial index on table MY_TABLE that is defined like: CREATE UNIQUE INDEX my_index ON MY_TABLE(CUSTOMER_ID, OWNER_ID) WHERE CLOSED_ON IS NULL; Then, I'm attempting an upsert using jOOQ final var insert = using(configuration) …
Daniel
  • 21,933
  • 14
  • 72
  • 101
1
vote
1 answer

How to apply cast in postgres values expression with JOOQ

For large 'in' conditions in Postgres the following IN (VALUES ('a'),('b'),('c')) can lead to much more efficient query plans than IN ('a','b','c') In JOOQ I can express this with Field f = ... Row1[] rows = new Row1[array.length]; for (int…
Yaun
  • 127
  • 2
  • 7
1 2 3
99
100