我正在尝试在 JDL Kotlin 中建立一个网站,但是 JDL 生成的实体和编辑表单存在问题。我有一个名为 的 JDL 实体Provider
,一个名为的实体Plan
需要引用它所属的提供者,以及一个名为的第三个实体PerDayPricing
,它同时引用Provider
and Plan
,所有这些都根据以下 JDL 配置:
entity Provider {
// [...]
}
entity Plan {
// [...]
}
entity PerDayPricing {
// [...]
}
relationship OneToMany {
Provider to Plan
}
relationship OneToMany {
Provider to PerDayPricing
Plan to PerDayPricing
}
service all with serviceImpl
但是,当我尝试在计划项上创建或设置提供者字段时,会出现以下错误:
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 字段时,会出现以下错误:
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 根据其配置创建文件,而不更改任何文件,这已经发生了。对方法名称的引用setPlans
甚至setPerDayPricings
不存在于代码库中,所以我假设它们是由 Kotlin 在后台生成的?
有谁知道发生了什么以及我该如何解决?
编辑:以下是实体类的签名(为简洁起见,删除了常规字段):
// 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
// 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
// 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