Issue
Does anyone know how I can solve this problem: 'Class 'Student' should have [public, protected] no-arg constructor'?
It's moaning about the relation to 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 added SchoolLesson on request
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 = "",
)
Solution
Never use data classes for @Entities. It causes a bunch of problems later on. Follow best practices listed here: https://www.jpa-buddy.com/blog/best-practices-and-common-pitfalls/.
Answered By - aleksey.stukalov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.