Spring Boot) No identifier specified for entity 에러 해결
[에러 메시지]
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-07-25 22:34:06.417 ERROR 3768 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: jpabook.jpashop.Member
h2 database 버전이 안 맞아서 그런가 하고 스프링 부트 버전에 맞는 버전으로 재설치하였으나, 같은 에러가 발생했다.
에러 메시지를 자세히 보니 엔티티를 찾을 수 없다는 메시지를 확인할 수 있었다.
구글링 해보니, 엔티티 클래스에서 import한 Id 애노테이션의 문제라고 했다.
import org.springframework.data.annotation.Id; 라고 되어 있다면,
import javax.persistence.Id; 로 수정해야 한다.
추가로 entityManagerFactory 관련 에러가 발생했을 때
javaassist가 없어서 그럴 수 있다고도 해서, build.gradle 파일의 dependencies에 다음 코드도 추가해주었다.
implementation group: 'org.javassist', name: 'javassist', version: '3.15.0-GA'
위와 같이 했더니 에러가 해결되었다.
참고
https://snowdeer.github.io/spring-boot/2019/11/28/spring-boot-no-identifier-specified-for-entity/