인프런 커뮤니티 질문&답변

주현님의 프로필 이미지
주현

작성한 질문수

실전! 스프링 부트와 JPA 활용1 - 웹 애플리케이션 개발

엔티티 클래스 개발2

데이터베이스연동문제

작성

·

56

0

해당 오류들이 나오면서 h2베이스에 연동이 되지 않습니다 ㅠㅠ 해결하는 방법이 있을까요?

2024-11-01T15:11:48.474+09:00 ERROR 84212 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: Property 'jpabook.jpshop.domain.Delivery.status' is annotated '@Enumerated' but its type 'jpabook.jpshop.domain.DeliveryStatus' is not an enum

2024-11-01T15:11:48.475+09:00 WARN 84212 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Property 'jpabook.jpshop.domain.Delivery.status' is annotated '@Enumerated' but its type 'jpabook.jpshop.domain.DeliveryStatus' is not an enum

2024-11-01T15:11:48.480+09:00 INFO 84212 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...

2024-11-01T15:11:48.495+09:00 INFO 84212 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.

2024-11-01T15:11:48.506+09:00 INFO 84212 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]

2024-11-01T15:11:48.548+09:00 INFO 84212 --- [ restartedMain] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.

2024-11-01T15:11:48.627+09:00 ERROR 84212 --- [ restartedMain] 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]: Property 'jpabook.jpshop.domain.Delivery.status' is annotated '@Enumerated' but its type 'jpabook.jpshop.domain.DeliveryStatus' is not an enum

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1775) ~[spring-beans-6.1.1.jar:6.1.1]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601) ~[spring-beans-6.1.1.jar:6.1.1]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-6.1.1.jar:6.1.1]

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[spring-beans-6.1.1.jar:6.1.1]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.1.jar:6.1.1]

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[spring-beans-6.1.1.jar:6.1.1]

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.1.1.jar:6.1.1]

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1173) ~[spring-context-6.1.1.jar:6.1.1]

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:936) ~[spring-context-6.1.1.jar:6.1.1]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:616) ~[spring-context-6.1.1.jar:6.1.1]

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.0.jar:3.2.0]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:753) ~[spring-boot-3.2.0.jar:3.2.0]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:455) ~[spring-boot-3.2.0.jar:3.2.0]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:323) ~[spring-boot-3.2.0.jar:3.2.0]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1342) ~[spring-boot-3.2.0.jar:3.2.0]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1331) ~[spring-boot-3.2.0.jar:3.2.0]

at jpabook.jpshop.JpashopApplication.main(JpashopApplication.java:10) ~[main/:na]

at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]

at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]

at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.2.0.jar:3.2.0]

Caused by: org.hibernate.AnnotationException: Property 'jpabook.jpshop.domain.Delivery.status' is annotated '@Enumerated' but its type 'jpabook.jpshop.domain.DeliveryStatus' is not an enum

at org.hibernate.boot.model.internal.BasicValueBinder.prepareBasicAttribute(BasicValueBinder.java:805) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.BasicValueBinder.setType(BasicValueBinder.java:374) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.PropertyBinder.makePropertyAndValue(PropertyBinder.java:261) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:297) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.PropertyBinder.createBasicBinder(PropertyBinder.java:1169) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.PropertyBinder.bindBasic(PropertyBinder.java:1071) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.PropertyBinder.bindProperty(PropertyBinder.java:890) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.PropertyBinder.buildProperty(PropertyBinder.java:788) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.PropertyBinder.processElementAnnotations(PropertyBinder.java:709) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.EntityBinder.processIdPropertiesIfNotAlready(EntityBinder.java:977) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.EntityBinder.handleIdentifier(EntityBinder.java:305) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.EntityBinder.bindEntityClass(EntityBinder.java:231) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.internal.AnnotationBinder.bindClass(AnnotationBinder.java:422) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:255) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:278) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:321) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1432) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1503) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final]

at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:75) ~[spring-orm-6.1.1.jar:6.1.1]

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376) ~[spring-orm-6.1.1.jar:6.1.1]

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-6.1.1.jar:6.1.1]

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-6.1.1.jar:6.1.1]

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352) ~[spring-orm-6.1.1.jar:6.1.1]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1822) ~[spring-beans-6.1.1.jar:6.1.1]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1771) ~[spring-beans-6.1.1.jar:6.1.1]

... 19 common frames omitted

Disconnected from the target VM, address: '127.0.0.1:55744', transport: 'socket'

Process finished with exit code 0

 

답변 2

0

주현님의 프로필 이미지
주현
질문자

딜리버리 쪽 코드를 잘못쳤네요! 해결됐습니다 !

0

안녕하세요, 인프런 AI 인턴입니다.

주현님이 겪고 계신 문제는 주로 @Enumerated 어노테이션의 대상이 enum 타입이 아니라 발생하는 오류입니다. 오류 메시지를 보면 jpabook.jpshop.domain.Delivery.status 필드가 @Enumerated로 설정되어 있는데, 해당 필드의 타입인 jpabook.jpshop.domain.DeliveryStatus가 enum이 아니라는 힌트를 제공합니다.

이 문제를 해결하기 위해서는 다음과 같은 해결 방법을 확인해보세요:

  1. DeliveryStatus 클래스 확인: DeliveryStatus 클래스가 enum 타입인지 확인하세요. 이 클래스를 enum으로 선언해야 합니다.
   public enum DeliveryStatus {
       READY, SHIPPED, DELIVERED
   }
  1. 필드 선언 확인: Delivery 클래스 내에 status 필드가 잘못 선언되지 않았는지 확인하세요. 타입이 DeliveryStatus로 되어 있어야 합니다.
   @Enumerated(EnumType.STRING)
   private DeliveryStatus status;
  1. 컴파일 에러 확인: 혹시 다른 컴파일 에러가 함께 있는지 IDE의 에러 로그를 확인하시고 관련된 부분을 수정해 주시기 바랍니다.

유사한 문제의 기존 해결책은 아래 링크에서 확인하실 수 있습니다:
- entity를 다만들고 실행을 해보는데 자꾸 에러가 나오는데 해결을 못하겠습니다.
- 엔티티 클래스 개발 2에서 에러가 나고, h2 데이터베이스가 업데이트가 되지 않아요

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

주현님의 프로필 이미지
주현
질문자

image.png

 

고쳤는데도 해당오류가 나옵니다.

image.png

H2에 테이블 생성이 되지 않는데 무엇이 문제인지 잘모르겠습니다...ㅠㅠ

주현님의 프로필 이미지
주현

작성한 질문수

질문하기