首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可空CompositeMoneyColumn,如何分配一个可空的MonetaryAmount?

问可空CompositeMoneyColumn,如何分配一个可空的MonetaryAmount?
EN

Stack Overflow用户
提问于 2022-02-24 08:05:56
回答 1查看 89关注 0票数 0

我有一个这样的专栏:

代码语言:javascript
复制
val notNullableAmount = compositeMoney(DECIMAL_PRECISION,
    DECIMAL_SCALE,
    "principal_sum",
    "principal_sum_currency")

在本例中,我可以将MonetaryAmount类型的值赋值给列,如下所示:

代码语言:javascript
复制
it[notNullableAmount] = ggnCollectionDocument.principalSum!!

但是,当我使用nullable()时,比如:

代码语言:javascript
复制
val principalSum = compositeMoney(DECIMAL_PRECISION,
    DECIMAL_SCALE,
    "principal_sum",
    "principal_sum_currency").nullable()

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

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-24 13:14:13

在表的声明中:

代码语言:javascript
复制
val principalSum = (compositeMoney(DECIMAL_PRECISION,
    DECIMAL_SCALE,
    "principal_sum",
    "principal_sum_currency").nullable()) as CompositeMoneyColumn<*, *, MonetaryAmount?>

在用法上:

代码语言:javascript
复制
it[principalSum] = ggnCollectionDocument.principalSum

与过载操作员:

代码语言:javascript
复制
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)
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71248852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档