gpt4 book ai didi

hibernate - InstantiationException:当使Entity字段在Kotlin中不可为空时,没有用于实体的默认构造函数

转载 作者:行者123 更新时间:2023-12-02 13:44:51 27 4
gpt4 key购买 nike

我有一个项目实体(如下所示)。当我尝试改变

var fullName: String?= null

至:
var fullName: String,

我突然从Hibernate收到InstantiationException:
org.hibernate.InstantiationException: No default constructor for entity:

在此之前,没有任何问题。可能出什么问题了?这是Entity类:
package no.inmeta.ris.project.model.entity

import org.hibernate.annotations.GenericGenerator
import java.util.*
import javax.persistence.*

@Entity
data class Project (

@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(columnDefinition = "BINARY(16)")
var id : UUID? = null,

var fullName: String,

var shortName: String? = null,

var prevRefId: String? = null,

var startDate: Date? = null,

var endDate: Date? = null,

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "Associated_Projects",
joinColumns = [JoinColumn(name = "associated_project")],
inverseJoinColumns = [JoinColumn(name = "second_associated_project") ])
var associatedProjects: List<Project?> = mutableListOf(),

var shortDescription: String? = null,

var summary: String? = null,

var url: String? = null,

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "Project_Types",
joinColumns = [JoinColumn(name = "project_id")],
inverseJoinColumns = [JoinColumn(name = "type_id") ])
var type: List<Type?> = mutableListOf()
)

最佳答案

为fullName参数提供默认值或使其可为空。

在您的代码中,它没有默认值,因此在生成的Java字节码中,Project类将没有构造函数而没有参数-它至少需要1个参数才能初始化fullName字段。

关于hibernate - InstantiationException:当使Entity字段在Kotlin中不可为空时,没有用于实体的默认构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59770113/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com