Repository navigation
Description
Problem
Every Kotlin generator in server/java/codegen-kotlin emits Exposed 0.x APIs (org.jetbrains.exposed.sql.*). Exposed 1.0 renamed those packages to org.jetbrains.exposed.v1.* and changed several signatures, so an adopter that uses the generated *Table objects cannot upgrade Exposed past 0.x.
That blocks a real fix. Exposed 0.x shares one IdentifierManagerApi per Database across all threads, and its identifier caches are plain LinkedHashMaps that getOrPut mutates on every query. Under concurrent queries they corrupt. The symptom is ClassCastException: class java.util.LinkedHashMap$Entry cannot be cast to class java.util.HashMap$TreeNode, or a thread that spins forever inside HashMap. A downstream Kotlin adopter hit the exception in its integration tests. A 16-thread stress test against exposed-core 0.55.0 reproduced it in 20 of 20 rounds, and 18 of those rounds hung. Upstream fixed it only in Exposed 1.3.0 (JetBrains/Exposed PR #2783, "fix thread-safety of IdentifierManagerApi identifier caches (#1704)"). The adopter currently carries a same-name shadow class to patch it, which is a stopgap.
What the generators emit today
| Generator | 0.x APIs in its output |
|---|---|
KotlinExposedTableGenerator |
Table, Column, ColumnType, ReferenceOption, CustomFunction + UUIDColumnType (the gen_random_uuid() default), json.jsonb, javatime.*; the emitted MetaInstantWithTimeZoneColumnType / MetaUriColumnType / MetaInetColumnType support files use IDateColumnType, statements.api.PreparedStatementApi and vendors.currentDialect |
KotlinTypeMapper |
uuid(col), javatime.date/datetime/time, json.jsonb, TextColumnType, UUIDColumnType |
KotlinRepositoryGenerator |
selectAll, insert, update, deleteWhere, ResultRow, SqlExpressionBuilder, statements.UpdateBuilder/UpdateStatement, transactions.transaction |
KotlinRelationsGenerator |
selectAll, Query, JoinType, and, or, SqlExpressionBuilder.eq |
KotlinSpringControllerGenerator |
selectAll, insert, update, deleteWhere, Op, SortOrder, castTo, SqlExpressionBuilder, TextColumnType, transactions.transaction |
KotlinStoredProcGenerator |
Transaction, transactions.transaction, the scalar *ColumnTypes, javatime.JavaInstantColumnType/JavaLocalDateColumnType, UUIDColumnType |
KotlinSpringConfigGenerator, KotlinValidatorGenerator |
org.jetbrains.exposed.sql / Table |
What 1.x output needs (from the official 1.0 migration guide)
- Package moves. Core types go to
org.jetbrains.exposed.v1.core.*. The JDBC-side functions (selectAll,insert,update,deleteWhere,Query,Database,transactions.transaction,SchemaUtils) go toorg.jetbrains.exposed.v1.jdbc.*. Alsov1.javatime.*andv1.json.*. - UUID columns.
Table.uuid()now mapskotlin.uuid.Uuid.java.util.UUIDcolumns must emitjavaUUID(col)(org.jetbrains.exposed.v1.core.java.javaUUID), andUUIDColumnTypemoves tov1.core.java.UUIDColumnType. This is the one silent trap: emittinguuid()still compiles, but it changes the Kotlin type. SqlExpressionBuilderis gone.eq,andand the other operators become top-level imports fromv1.core, anddeleteWhere/update(where = …)lambdas lose their receiver.- Custom column types.
IColumnType.readObject(rs: ResultSet, …)becomesreadObject(rs: RowApi, …).currentDialectmoves, and the metadata-query methods move tocurrentDialectMetadata. This affects the emittedMeta*ColumnTypesupport files. - Transactions. The receiver type becomes
JdbcTransaction, andTransactionManager.defaultDatabaseno longer defaults to the last registered database. - Consumers. Exposed 1.x needs Kotlin ≥ 2.2; 1.3.0 is built against stdlib 2.3.20.
spring-transaction1.3.0 is built against Spring 6.2 / Boot 3.5.
Proposed shape
- A generator arg such as
exposedApi = 0 | 1, defaulting to0, so existing adopters' output stays byte-identical. Every Kotlin generator above honours it. The alternative is a clean major-version cut to 1.x only, which is the maintainer's call. - Extend
CodegenCompileConformanceTest(and theintegration-tests-kotlinreference module) to compile the generated output against Exposed 1.3.x as well as 0.x. A mode that is never compiled will rot. - Document the Kotlin and Spring floor that the 1.x mode implies.
Acceptance
- For the same metadata,
exposedApi = 1output compiles against exposed-core/jdbc/java-time/json 1.3.x, andexposedApi = 0output is unchanged. - UUID columns keep
Column<java.util.UUID>under 1.x (javaUUID, neveruuid). - The emitted custom column types round-trip through a real JDBC read under 1.x.
Activity
feat(codegen-kotlin): add exposedApi option for Exposed 1.x output
test(codegen-kotlin): add Exposed 1.x compile + round-trip check module
docs(ports): document exposedApi and the Exposed 1.x floor for Kotlin
fix(codegen-kotlin): thread v1 operator imports through the controlle…
test(codegen-kotlin): add an exposedApi=1 controller-tier compile pass
chore: register codegen-kotlin-exposed1x-check as a reactor-excluded pom
docs(ports): make the Kotlin exposedApi coverage claim match what's p…
dmealing commentedon Oct 3, 2026
Shipped in 1.0.12 (Maven Central 8.0.12):
exposedApi = 0 | 1on every Kotlin generator; 1.x output compile-checked with Kotlin 2.2 against Exposed 1.3.1 and real Spring 6.2, custom column types round-tripped through Postgres. See docs/ports/kotlin.md.