jooq: jOOQ 3.21.9 on Spring Boot 4.2.0 - codegen from Flyway migrations, typed queries, MULTISET, transactions, Testcontainers, fourteen real transcripts

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7h4ZNF4BDUpJk3Zou
This commit is contained in:
Ankur Mhatre
2026-11-29 02:25:52 +05:30
co-authored by Claude Sonnet 5.5
parent 8d8c28e2e5
commit 3f061c5e5d
57 changed files with 3319 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
$ scripts/codegen.sh
generated files:
src/main/java/com/ankurm/jooq/generated/DefaultCatalog.java
src/main/java/com/ankurm/jooq/generated/Indexes.java
src/main/java/com/ankurm/jooq/generated/Keys.java
src/main/java/com/ankurm/jooq/generated/Public.java
src/main/java/com/ankurm/jooq/generated/Tables.java
src/main/java/com/ankurm/jooq/generated/enums/Genre.java
src/main/java/com/ankurm/jooq/generated/tables/Author.java
src/main/java/com/ankurm/jooq/generated/tables/Book.java
src/main/java/com/ankurm/jooq/generated/tables/Review.java
src/main/java/com/ankurm/jooq/generated/tables/pojos/Author.java
src/main/java/com/ankurm/jooq/generated/tables/pojos/Book.java
src/main/java/com/ankurm/jooq/generated/tables/pojos/Review.java
src/main/java/com/ankurm/jooq/generated/tables/records/AuthorRecord.java
src/main/java/com/ankurm/jooq/generated/tables/records/BookRecord.java
src/main/java/com/ankurm/jooq/generated/tables/records/ReviewRecord.java
checksum of generated sources before: 2b5f174e286873e9
checksum of generated sources after: 2b5f174e286873e9
+4
View File
@@ -0,0 +1,4 @@
files regenerated from the live schema: 15
files committed in src/main/java: 15
byte-identical files: 15
verdict: committed generated code matches Flyway V1 + V2
@@ -0,0 +1,10 @@
DSLContext dialect: POSTGRES
Flyway history: [1 bookshop success=true, 2 book isbn success=true]
listener providers on the DSLContext: 2
transaction provider: org.springframework.boot.jooq.autoconfigure.SpringTransactionProvider
plain ExecuteListener bean calls so far: 0 (bean exists: true)
SQL: insert into "public"."book" ("author_id", "title", "genre", "price", "published_on", "stock", "isbn") values (?, ?, cast(? as "public"."genre"), ?, cast(? as date), ?, ?) returning "public"."book"."id", "public"."book"."author_id", "public"."book"."title", "public"."book"."genre", "public"."book"."price", "public"."book"."published_on", "public"."book"."stock", "public"."book"."isbn"
Returned POJO (a generated Java record): Book (7, 1, Returning Demo, TECH, 10.50, 2026-02-02, 1, 978-9-99)
insert with explicit id on GENERATED ALWAYS column: ERROR: cannot insert a non-DEFAULT value into column "id"
+15
View File
@@ -0,0 +1,15 @@
SQL: select "public"."book"."title", "public"."author"."name", "public"."book"."genre", "public"."book"."price" from "public"."book" join "public"."author" on "public"."author"."id" = "public"."book"."author_id" order by "public"."book"."title"
row: BookRow[title=Compilers for Humans, author=Grace Hopper, genre=TECH, price=45.00]
row: BookRow[title=Debugging a Moth, author=Grace Hopper, genre=HISTORY, price=18.75]
row: BookRow[title=Kata of Clean Code, author=Kenji Tanaka, genre=TECH, price=39.90]
row: BookRow[title=Notes on the Analytical Engine, author=Ada Lovelace, genre=SCIENCE, price=24.50]
row: BookRow[title=Poetical Science, author=Ada Lovelace, genre=FICTION, price=12.00]
row: BookRow[title=Tokyo Trains, author=Kenji Tanaka, genre=HISTORY, price=22.00]
SQL: select "public"."book"."title", "public"."author"."name", "public"."book"."genre", "public"."book"."price" from "public"."book" join "public"."author" on "public"."author"."id" = "public"."book"."author_id" where "public"."book"."genre" = cast(? as "public"."genre") order by "public"."book"."title"
row: BookRow[title=Compilers for Humans, author=Grace Hopper, genre=TECH, price=45.00]
row: BookRow[title=Kata of Clean Code, author=Kenji Tanaka, genre=TECH, price=39.90]
SQL: select "public"."book"."title", "public"."author"."name", "public"."book"."genre", "public"."book"."price" from "public"."book" join "public"."author" on "public"."author"."id" = "public"."book"."author_id" where (lower("public"."book"."title") like ('%' || replace(replace(replace(lower(?), '!', '!!'), '%', '!%'), '_', '!_') || '%') escape '!' and "public"."book"."genre" = cast(? as "public"."genre") and "public"."book"."price" <= ? and "public"."author"."country" = ?) order by "public"."book"."title"
row: BookRow[title=Kata of Clean Code, author=Kenji Tanaka, genre=TECH, price=39.90]
+11
View File
@@ -0,0 +1,11 @@
statements sent: 1
SQL: select "public"."book"."title", (select coalesce(jsonb_agg(jsonb_build_array(t."v0", t."v1")), jsonb_build_array()) from (select "public"."review"."rating" as "v0", "public"."review"."body" as "v1" from "public"."review" where "public"."review"."book_id" = "public"."book"."id" order by "public"."review"."id") as t) from "public"."book" order by "public"."book"."title"
BookWithReviews[title=Compilers for Humans, reviews=[ReviewView[rating=5, body=Changed how I think], ReviewView[rating=4, body=Great examples], ReviewView[rating=5, body=Buy it]]]
BookWithReviews[title=Debugging a Moth, reviews=[]]
BookWithReviews[title=Kata of Clean Code, reviews=[ReviewView[rating=2, body=Too many koans]]]
BookWithReviews[title=Notes on the Analytical Engine, reviews=[ReviewView[rating=5, body=Foundational], ReviewView[rating=4, body=Dense but worth it]]]
BookWithReviews[title=Poetical Science, reviews=[ReviewView[rating=3, body=Charming]]]
BookWithReviews[title=Tokyo Trains, reviews=[ReviewView[rating=4, body=Lovely photographs]]]
flat LEFT JOIN returns 9 rows for 6 books; MULTISET returns 6 rows
+11
View File
@@ -0,0 +1,11 @@
SQL: with "ratings" as (select "public"."book"."genre", "public"."book"."title", avg(cast("public"."review"."rating" as double precision)) as "avg_rating" from "public"."book" join "public"."review" on "public"."review"."book_id" = "public"."book"."id" group by "public"."book"."genre", "public"."book"."title"), "ranked" as (select "ratings"."genre", "ratings"."title", "ratings"."avg_rating", rank() over (partition by "ratings"."genre" order by "ratings"."avg_rating" desc, "ratings"."title") as "rnk" from "ratings") select "ranked"."genre", "ranked"."title", "ranked"."avg_rating", "ranked"."rnk" from "ranked" where "ranked"."rnk" = ? order by "ranked"."genre"
GenreLeader[genre=FICTION, title=Poetical Science, avgRating=3.0, rank=1]
GenreLeader[genre=SCIENCE, title=Notes on the Analytical Engine, avgRating=4.5, rank=1]
GenreLeader[genre=HISTORY, title=Tokyo Trains, avgRating=4.0, rank=1]
GenreLeader[genre=TECH, title=Compilers for Humans, avgRating=4.666666666666667, rank=1]
SQL: select "public"."author"."name", count(*), sum(("public"."book"."price" * "public"."book"."stock")) from "public"."author" join "public"."book" on "public"."book"."author_id" = "public"."author"."id" group by "public"."author"."name" order by sum(("public"."book"."price" * "public"."book"."stock")) desc
LeaderboardRow[author=Kenji Tanaka, books=2, catalogueValue=544.80]
LeaderboardRow[author=Grace Hopper, books=2, catalogueValue=315.00]
LeaderboardRow[author=Ada Lovelace, books=2, catalogueValue=305.00]
+8
View File
@@ -0,0 +1,8 @@
SQL: insert into "public"."book" ("author_id", "title", "genre", "price", "published_on", "stock", "isbn") values (?, ?, cast(? as "public"."genre"), ?, cast(? as date), ?, ?) on conflict ("isbn") do update set "stock" = ("public"."book"."stock" + ?) returning "public"."book"."id", "public"."book"."author_id", "public"."book"."title", "public"."book"."genre", "public"."book"."price", "public"."book"."published_on", "public"."book"."stock", "public"."book"."isbn"
first call -> stock 4 (inserted)
second call -> stock 8 (conflict, stock added); same id: true
page 1 SQL: select "public"."book"."id" from "public"."book" where "public"."book"."id" > ? order by "public"."book"."id" fetch next ? rows only
page 1: [1, 2, 3] next=3
page 2 SQL: select "public"."book"."id" from "public"."book" where "public"."book"."id" > ? order by "public"."book"."id" fetch next ? rows only
page 2: [4, 5, 6] next=6
@@ -0,0 +1,3 @@
dsl.fetch("select isbnn from book") compiles fine and fails at runtime:
exception type: org.springframework.jdbc.BadSqlGrammarException
root cause: ERROR: column "isbnn" does not exist
+8
View File
@@ -0,0 +1,8 @@
seeded authors: 3
1. no @Transactional, exception after 2 inserts -> author persisted: true, book persisted: true
2. @Transactional, RuntimeException -> author persisted: false, book persisted: false
3. @Transactional, checked IOException -> author persisted: true, book persisted: true
4. @Transactional(rollbackFor=Exception.class) -> author persisted: false, book persisted: false
5. dsl.transaction inside @Transactional, inner fails, caught -> caught inner failure, outer continues (author id 8)
outer author persisted: true, inner author persisted: false
6. dsl.transaction alone: success persisted: true; failure persisted: false
@@ -0,0 +1,8 @@
per-class @Container, two test classes sharing one cached Spring context (hikari connection-timeout shortened to 2 s)
5 Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 2000ms (total=0, active=0, idle=0, waiting=0)
1 Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 2001ms (total=0, active=0, idle=0, waiting=0)
10 WARN 4798 --- [jooq-demo] [ main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@HASH (This connection has been closed.). Possibly consider using a shorter maxLifetime value
1 [ERROR] Tests run: 6, Failures: 0, Errors: 6, Skipped: 0, Time elapsed: 20.43 s <<< FAILURE! -- in com.ankurm.jooq.QueryTests
1 [ERROR] Tests run: 7, Failures: 0, Errors: 6, Skipped: 0
5 org.springframework.dao.TransientDataAccessResourceException: jOOQ; SQL [TRUNCATE review, book, author RESTART IDENTITY CASCADE]; HikariPool-1 - Connection is not available, request timed out after 2000ms (total=0, active=0, idle=0, waiting=0)
1 org.springframework.dao.TransientDataAccessResourceException: jOOQ; SQL [TRUNCATE review, book, author RESTART IDENTITY CASCADE]; HikariPool-1 - Connection is not available, request timed out after 2001ms (total=0, active=0, idle=0, waiting=0)
+26
View File
@@ -0,0 +1,26 @@
== A. wrong type: BOOK.PRICE.eq("12.50") ==
src/main/java/com/ankurm/jooq/WrongType.java:[10,53] no suitable method found for eq(java.lang.String)
method org.jooq.Field.eq(java.math.BigDecimal) is not applicable
(argument mismatch; java.lang.String cannot be converted to java.math.BigDecimal)
method org.jooq.Field.eq(org.jooq.Select<? extends org.jooq.Record1<java.math.BigDecimal>>) is not applicable
(argument mismatch; java.lang.String cannot be converted to org.jooq.Select<? extends org.jooq.Record1<java.math.BigDecimal>>)
method org.jooq.Field.eq(org.jooq.Field<java.math.BigDecimal>) is not applicable
(argument mismatch; java.lang.String cannot be converted to org.jooq.Field<java.math.BigDecimal>)
method org.jooq.Field.eq(org.jooq.QuantifiedSelect<? extends org.jooq.Record1<java.math.BigDecimal>>) is not applicable
(argument mismatch; java.lang.String cannot be converted to org.jooq.QuantifiedSelect<? extends org.jooq.Record1<java.math.BigDecimal>>)
== B. typo: BOOK.ISBNN ==
src/main/java/com/ankurm/jooq/Typo.java:[10,31] cannot find symbol
symbol: variable ISBNN
location: variable BOOK of type com.ankurm.jooq.generated.tables.Book
== C. regenerate from schema version 1 only (no isbn column), compile the unchanged application ==
src/main/java/com/ankurm/jooq/BookshopRepository.java:[49,26] cannot find symbol
symbol: variable ISBN
location: variable BOOK of type com.ankurm.jooq.generated.tables.Book
src/main/java/com/ankurm/jooq/BookshopRepository.java:[131,33] cannot find symbol
symbol: variable ISBN
location: variable BOOK of type com.ankurm.jooq.generated.tables.Book
src/main/java/com/ankurm/jooq/BookshopRepository.java:[130,26] cannot find symbol
symbol: variable ISBN
location: variable BOOK of type com.ankurm.jooq.generated.tables.Book
+5
View File
@@ -0,0 +1,5 @@
added src/main/resources/db/migration/V3__book_subtitle.sql, did NOT regenerate
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 26.50 s <<< FAILURE! -- in com.ankurm.jooq.CodegenDriftTest
org.opentest4j.AssertionFailedError: generated code is stale, run scripts/codegen.sh. Differing files: [tables/Book.java, tables/pojos/Book.java, tables/records/BookRecord.java] ==> expected: <true> but was: <false>
[ERROR] CodegenDriftTest.committedGeneratedCodeMatchesMigrations:64 generated code is stale, run scripts/codegen.sh. Differing files: [tables/Book.java, tables/pojos/Book.java, tables/records/BookRecord.java] ==> expected: <true> but was: <false>
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
+6
View File
@@ -0,0 +1,6 @@
DSLContext present: true (dialect POSTGRES)
BookshopRepository in context: false
StockService in context: false
SqlLog in context: false
Flyway ran (schema has tables): true
author rows via typed API: 0
+5
View File
@@ -0,0 +1,5 @@
com.ankurm.jooq.JooqSliceTest : Starting JooqSliceTest using Java 25.0.5.1 with PID N
org.flywaydb.core.FlywayExecutor : Database: jdbc:postgresql://localhost:PORT/test?loggerLevel=OFF (PostgreSQL 17.12)
o.f.core.internal.command.DbMigrate : Successfully applied 2 migrations to schema "public", now at version v2 (execution time 00:00.021s)
Thank you for using jOOQ 3.21.9 (Build date: 2026-09-24T13:35:23Z)
o.j.i.D.logVersionSupport : Version mismatch : Database version is older than what dialect SQLDialect.POSTGRES supports: 17.12. Consider https://www.jooq.org/download/support-matrix to see what jOOQ version and edition supports which RDBMS versions.
@@ -0,0 +1,4 @@
flyway-database-postgresql removed from the application dependencies
Caused by: org.flywaydb.core.api.FlywayException: Unsupported Database: PostgreSQL 17.12
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 9.266 s <<< FAILURE! -- in com.ankurm.jooq.JooqSliceTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0