diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpdateBuilder.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpdateBuilder.kt index f709481b2b..2bd36a79a9 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpdateBuilder.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpdateBuilder.kt @@ -28,7 +28,7 @@ abstract class UpdateBuilder(type: StatementType, targets: List) : } @LowPriorityInOverloadResolution - open operator fun < S> set(column: Column, value: S) { + open operator fun set(column: Column, value: S) { require(column.columnType.nullable || (value != null && value !is Op.NULL)) { "Trying to set null to not nullable column $column" } @@ -66,7 +66,7 @@ abstract class UpdateBuilder(type: StatementType, targets: List
) : open operator fun set(column: Column, value: Query) = update(column, wrapAsExpression(value)) - open operator fun set(column: CompositeColumn, value: S) { + open operator fun set(column: CompositeColumn, value: S) { column.getRealColumnsWithValues(value).forEach { (realColumn, itsValue) -> set(realColumn as Column, itsValue) } } diff --git a/exposed-money/src/test/kotlin/org/jetbrains/exposed/sql/money/MoneyTests.kt b/exposed-money/src/test/kotlin/org/jetbrains/exposed/sql/money/MoneyTests.kt index 8a0102c685..d1e305a0e7 100644 --- a/exposed-money/src/test/kotlin/org/jetbrains/exposed/sql/money/MoneyTests.kt +++ b/exposed-money/src/test/kotlin/org/jetbrains/exposed/sql/money/MoneyTests.kt @@ -78,6 +78,26 @@ open class MoneyBaseTest : DatabaseTestsBase() { } } + @Test + fun testNullableCompositeColumnInsertAndSelect() { + val table = object : IntIdTable("Table") { + val composite_money = compositeMoney(8, AMOUNT_SCALE, "composite_money").nullable() + } + + val usdAmount = Money.of(BigDecimal.TEN, "USD") + + withTables(table) { + val id = table.insertAndGetId { + it[composite_money] = usdAmount + } + + val resultRow = table.select { table.id.eq(id) }.single() + val result = resultRow[table.composite_money] + + assertEquals(usdAmount, result) + } + } + private fun testInsertedAndSelect(toInsert: Money?) { withTables(Account) { val accountID = Account.insertAndGetId {