JPA Entity에는 디폴트 생성자가 필수 - No default constructor for entity

cozzin·2024년 5월 28일
0
% curl -X GET http://localhost:8080/users/1
{"timestamp":"2024-05-28T13:55:34.533+00:00","status":500,"error":"Internal Server Error","path":"/users/1"}%      
2024-05-28T22:55:34.528+09:00 ERROR 30223 --- [WorkWell] [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.orm.jpa.JpaSystemException: No default constructor for entity 'com.cozzin.workwell.user.model.User'] with root cause

Spring Data JPA에서 사용되는 Entity 클래스에는 디폴트 생성자가 반드시 있어야한다
출처: https://itvillage.tistory.com/51 [IT Village:티스토리]

기존

@Entity
@Table(name = "users")
data class User(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long = 0,
    val name: String,
    val password: String,
    val email: String
)

변경

@Entity
@Table(name = "users")
data class User(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long = 0,
    val name: String,
    val password: String,
    val email: String
) {
    // No-argument constructor
    constructor() : this(0, "", "", "")
}
profile
Software Engineer

0개의 댓글