인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

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

어떠아하니님의 프로필 이미지
어떠아하니

작성한 질문수

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

엔티티 클래스 개발2

엔티티클래스 개발 후 오류입니다.

작성

·

1.2K

0

안녕하세요

추석연휴 잘 보내셨나요 ? ^^

강의 잘 듣고 있습니다.

STS에서 작업중입니다.(자바버전은 15, h2버전은 강의사양과 동일)

아래와 같은 에러가 나는데 어떤 원인일까요..?

아래는 OrderItem 소스입니다

@Entity

@Table(name = "order_item")

@Getter @Setter

public class OrderItem {

@Id @GeneratedValue

@Column(name = "order_item_id")

private Long id;

@ManyToOne

@JoinColumn(name = "item_id") 

private Item item; //주문 상품

@ManyToOne

@JoinColumn(name = "order_id") 

private Order order; //주문

private int orderPrice; //주문 가격

private int count; //주문 수량

}

에러내용 ↓

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: @OneToOne or @ManyToOne on jpabook.jpashop.domain.OrderItem.item references an unknown entity: org.hibernate.cache.spi.support.AbstractReadWriteAccess$Item

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514) ~[spring-beans-5.1.18.RELEASE.jar:5.1.18.RELEASE]

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

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

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319) ~[spring-beans-5.1.18.RELEASE.jar:5.1.18.RELEASE]

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

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1106) ~[spring-context-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.17.BUILD-SNAPSHOT.jar:2.1.17.BUILD-SNAPSHOT]

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) ~[spring-boot-2.1.17.BUILD-SNAPSHOT.jar:2.1.17.BUILD-SNAPSHOT]

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) ~[spring-boot-2.1.17.BUILD-SNAPSHOT.jar:2.1.17.BUILD-SNAPSHOT]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.17.BUILD-SNAPSHOT.jar:2.1.17.BUILD-SNAPSHOT]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.1.17.BUILD-SNAPSHOT.jar:2.1.17.BUILD-SNAPSHOT]

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) ~[spring-boot-2.1.17.BUILD-SNAPSHOT.jar:2.1.17.BUILD-SNAPSHOT]

at jpabook.jpashop.JpashopApplication.main(JpashopApplication.java:12) ~[main/:na]

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]

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

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

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

at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.1.17.BUILD-SNAPSHOT.jar:2.1.17.BUILD-SNAPSHOT]

Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on jpabook.jpashop.domain.OrderItem.item references an unknown entity: org.hibernate.cache.spi.support.AbstractReadWriteAccess$Item

at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:97) ~[hibernate-core-5.3.18.Final.jar:5.3.18.Final]

at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processEndOfQueue(InFlightMetadataCollectorImpl.java:1827) ~[hibernate-core-5.3.18.Final.jar:5.3.18.Final]

at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1771) ~[hibernate-core-5.3.18.Final.jar:5.3.18.Final]

at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1658) ~[hibernate-core-5.3.18.Final.jar:5.3.18.Final]

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

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

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

at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) ~[spring-orm-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378) ~[spring-orm-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1828) ~[spring-beans-5.1.18.RELEASE.jar:5.1.18.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1765) ~[spring-beans-5.1.18.RELEASE.jar:5.1.18.RELEASE]

... 21 common frames omitted

답변 2

1

ㅋㅋ이런 초보적인 실수를!!!

감사합니다. ㅋㅋ개발룰 관련해서 질문드릴게 있는데

실습후에  정리해서 한번 여쭤볼게요!!

0

김영한님의 프로필 이미지
김영한
지식공유자

안녕하세요. 어떠아하니님

오류 로그를 보니까, OrderItem 클래스의 item 참조 부분이 잘못되었습니다.

직접 만드신 Item 클래스를 import 해야하는데, org.hibernate.cache.spi.support.AbstractReadWriteAccess$Item를 import 한 것 같아요^^!

@OneToOne or @ManyToOne on jpabook.jpashop.domain.OrderItem.item references an unknown entity: org.hibernate.cache.spi.support.AbstractReadWriteAccess$Item

확인부탁드립니다.

어떠아하니님의 프로필 이미지
어떠아하니

작성한 질문수

질문하기