본문 바로가기
스프링/스프링

[Spring] 오류 해결: org.hibernate.AnnotationException: No identifier specified for entity

by 책 읽는 개발자_테드 2021. 4. 15.
반응형

문제 

 

스프링에서 Entity 클래스를 다음과 같이 작성했다.

 

@Entity

public class User {

   @Id
   private Long id;
   private String firstName;
   private int age;
   private String email;
}

 

작성하는 중 분명 @Id 어노테이션을 갖는 필드가 존재함에도 다음과 같은 에러를 뿜으며 애플리케이션 실행이 중지되었다. 

 

 

해결

 

잘못된 패키지에서 Id 클래스를 import 하고 있었다. 다음과 같이 변경하여 해결할 수 있었다.

import org.springframework.data.annotation.Id;  변경 -> import javax.persistence.Id;

반응형

댓글