首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当尝试从JHipster Kotlin中的另一个实体引用一个JDL实体时,抛出"Parameter specified as non-null is null“。

当尝试从JHipster Kotlin中的另一个实体引用一个JDL实体时,抛出"Parameter specified as non-null is null“。
EN

Stack Overflow用户
提问于 2020-06-04 04:11:44
回答 1查看 456关注 0票数 0

我正在尝试用JDL Kotlin建立一个网站,但我在JDL生成的实体和编辑表单方面遇到了问题。我有一个名为Provider的JDL实体,一个名为Plan的实体,它需要引用它所属的提供者,还有一个名为PerDayPricing的实体,它同时引用ProviderPlan,所有这些都符合以下JDL配置:

代码语言:javascript
复制
entity Provider {
    // [...]
}

entity Plan {
    // [...]
}

entity PerDayPricing {
    // [...]
}

relationship OneToMany {
    Provider to Plan
}

relationship OneToMany {
    Provider to PerDayPricing
    Plan to PerDayPricing
}

service all with serviceImpl

但是,当我尝试在Plan item上创建或设置Provider字段时,它显示以下错误:

代码语言:javascript
复制
WARN [PID] --- [ XNIO-1 task-10] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageConversionException: JSON conversion problem: Parameter specified as non-null is null: method com.example.project.domain.Plan.setPerDayPricings, parameter <set-?>; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Parameter specified as non-null is null: method com.example.project.domain.Plan.setPerDayPricings, parameter <set-?> (through reference chain: com.example.project.domain.Plan["perDayPricings"])]

这里引用了PerDayPricing,尽管我没有更改它的任何项。当我尝试在PerDayPricing项上设置Provider字段时,出现以下错误:

代码语言:javascript
复制
WARN [PID] --- [ XNIO-1 task-32] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageConversionException: JSON conversion problem: Parameter specified as non-null is null: method com.example.project.domain.Provider.setPlans, parameter <set-?>; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Parameter specified as non-null is null: method com.example.project.domain.Provider.setPlans, parameter <set-?> (through reference chain: com.example.project.domain.PerDayPricing["provider"]->com.example.project.domain.Provider["plans"])]

我实际上不知道这里发生了什么,因为我没有太多使用JHipster的经验。我只是导入了JDL源文件,并让JHipster基于其配置创建文件,而无需更改任何文件,而且这种情况已经发生了。在代码库中甚至不存在对方法名setPlanssetPerDayPricings的引用,所以我假设它们是由Kotlin在后台生成的?

有没有人知道发生了什么事,我该怎么解决它?

编辑:以下是实体类的签名(为简洁起见,删除了常规字段):

代码语言:javascript
复制
// src/main/kotlin/domain/Provider.kt

@Entity
@Table(name = "plan")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
data class Plan(
    // [...]

    @OneToMany(mappedBy = "plan")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    var perDayPricings: MutableSet<PerDayPricing> = mutableSetOf(),

    @OneToMany(mappedBy = "plan")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    var fixedDurationPricings: MutableSet<FixedDurationPricing> = mutableSetOf(),

    @ManyToOne @JsonIgnoreProperties("plans")
    var provider: Provider? = null

    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
) : Serializable
代码语言:javascript
复制
// src/main/kotlin/domain/Plan.kt

@Entity
@Table(name = "provider")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
data class Provider(
    // [...]

    @OneToMany(mappedBy = "provider")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    var plans: MutableSet<Plan> = mutableSetOf(),

    @OneToMany(mappedBy = "provider")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    var perDayPricings: MutableSet<PerDayPricing> = mutableSetOf(),

    @OneToMany(mappedBy = "provider")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    var fixedDurationPricings: MutableSet<FixedDurationPricing> = mutableSetOf()

    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
) : Serializable
代码语言:javascript
复制
// src/main/kotlin/domain/PerDayPricing.kt

/**
 * A PerDayPricing.
 */
@Entity
@Table(name = "per_day_pricing")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
data class PerDayPricing(
    // [...]

    @ManyToOne @JsonIgnoreProperties("perDayPricings")
    var provider: Provider? = null,

    @ManyToOne @JsonIgnoreProperties("perDayPricings")
    var plan: Plan? = null

    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
) : Serializable
EN

回答 1

Stack Overflow用户

发布于 2020-06-04 05:49:14

如果编译器生成数据类,那么编译器将为您生成setter和getter。我想,当您想要将实体彼此设置时,您没有提供异常中的那些字段。默认情况下,Kotlin不支持空值。所以要么必须提供这些字段,要么将类型标记为可空?(问号)在类型的和处。例如

var perDayPricings:String?

您应该使用给定的代码更新问题,这样我们就可以看到问题出在哪里。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62181918

复制
相关文章

相似问题

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