kotlin - kotlin 中的 JPA 错误:“学生”类应该有 [public, protected] no-arg 构造函数
问题描述
有谁知道我该如何解决这个问题:'班级'学生'应该有[公共,受保护的]无参数构造函数'?
它在抱怨与SchoolLesson
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
@Entity
data class Student(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = -1,
@ManyToOne
@NotNull
@JoinColumn(name = "school_lesson_id", referencedColumnName = "id")
val report: SchoolLesson,
)
#EDIT 应要求添加了 SchoolLesson
import javax.persistence.*
import javax.validation.constraints.NotNull
@Entity
data class SchoolLesson(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
val id: Long = -1,
@NotNull
val name: String = "",
)
解决方案
您可以使用无参数编译器插件,它将添加“一个额外的零参数构造函数”。详细信息在链接中。
推荐阅读
- python - 未加载库:@rpath/libomp.dylib 原因:找不到图像
- gradle - Gradle 构建失败并出现 HTTPS required 错误
- ffmpeg - 使用显示方向 SEI 旋转 h264 视频
- javascript - 如何在按钮单击时将数据从组件发送到工作人员?
- javascript - React 测试库:测试失败样式(从 MUI 中选择 + 表单控件)
- sql - 类似的 sql 一个可以执行,一个在 oracle 12 中出错
- elixir - 如何在 Elixir/Phoenix 中删除小数点后的尾随零?
- python - 当父进程死亡时,如何杀死使用 python subprocess.Popen() 创建的 docker?
- laravel - Laravel5.8 Pusher 事件 500 内部服务器错误
- c++ - 随机对象生成器 C++