可为空的 CompositeMoneyColumn,如何分配可为空的 MonetaryAmount?

Nullable CompositeMoneyColumn, how to assign a nullable MonetaryAmount?

我有这样一个专栏:

val notNullableAmount = compositeMoney(DECIMAL_PRECISION,
    DECIMAL_SCALE,
    "principal_sum",
    "principal_sum_currency")

在这种情况下,我可以将 MonetaryAmount 类型的值分配给列,例如:

it[notNullableAmount] = ggnCollectionDocument.principalSum!!

但是当我像这样使用 nullable() 时:

val principalSum = compositeMoney(DECIMAL_PRECISION,
    DECIMAL_SCALE,
    "principal_sum",
    "principal_sum_currency").nullable()

那我不能再分配 MonetaryAmount 了。它抱怨一些通用错误消息:

None of the following functions can be called with the arguments supplied.
set(Column<TypeVariable(ID)>, TypeVariable(E))   where S = TypeVariable(S), ID = TypeVariable(ID), E = TypeVariable(E) for    fun <S, ID : EntityID<S>, E : Expression<S>> set(column: Column<ID>, value: E): Unit defined in org.jetbrains.exposed.sql.statements.InsertStatement
set(Column<TypeVariable(ID)>, TypeVariable(S))   where S = TypeVariable(S), E = TypeVariable(E), ID = TypeVariable(ID) for    fun <S : Comparable<S>, E : S, ID : EntityID<E>?> set(column: Column<ID>, value: S): Unit defined in org.jetbrains.exposed.sql.statements.InsertStatement
set(Column<TypeVariable(S)>, TypeVariable(S))   where S = TypeVariable(S) for    fun <S> set(column: Column<S>, value: S): Unit defined in org.jetbrains.exposed.sql.statements.InsertStatement
set(Column<TypeVariable(S)>, Query)   where S = TypeVariable(S) for    fun <S> set(column: Column<S>, value: Query): Unit defined in org.jetbrains.exposed.sql.statements.InsertStatement
set(Column<TypeVariable(T)>, TypeVariable(E))   where T = TypeVariable(T), S = TypeVariable(S), E = TypeVariable(E) for    fun <T, S : T, E : Expression<S>> set(column: Column<T>, value: E): Unit defined in org.jetbrains.exposed.sql.statements.InsertStatement
set(CompositeColumn<TypeVariable(S)>, TypeVariable(S))   where S = TypeVariable(S) for    fun <S : Any> set(column: CompositeColumn<S>, value: S): Unit defined in org.jetbrains.exposed.sql.statements.InsertStatement

在 table 的声明中:

val principalSum = (compositeMoney(DECIMAL_PRECISION,
    DECIMAL_SCALE,
    "principal_sum",
    "principal_sum_currency").nullable()) as CompositeMoneyColumn<*, *, MonetaryAmount?>

在用法中:

it[principalSum] = ggnCollectionDocument.principalSum

使用重载运算符:

private operator fun InsertStatement<*>.set(column: CompositeMoneyColumn<*,*,MonetaryAmount?>, value: MonetaryAmount?) {
   val insertStatement = this
   insertStatement.set(column.amount as Column<BigDecimal?>, value?.number?.numberValue(BigDecimal::class.java))
   insertStatement.set(column.currency as Column<CurrencyUnit?>, value?.currency)
}