Kotlin 2.1.0
spring-boot-starter-data-jdbc 3.4.0
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Table
@Table("TEST_SIMPLE_TABLE")
data class SimpleTable(
@Id
var simpleId: Int,
var name: String
)
val simpleTable = SimpleTable(simpleId = 0, name = "something")
jdbcAggregateTemplate.insert(entity)
this generates SQL without SIMPLE_ID column and obviously fails:
INSERT INTO "TEST_SIMPLE_TABLE" ("NAME") VALUES ('something')
java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into ("TEST_SIMPLE_TABLE"."SIMPLE_ID")
it is related with Kotlin's Int bytecode mapping (Int -> int, Int? -> java.lang.Integer)
- when
simpleId is set to other value than 0, it works
- when
simpleId is defined as Int? , it works
so Int? is workaround, but not ideal to loose nullability check.
Looks like bug to me.