• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

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

24.04.01 16:00 작성 조회수 172

2

학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.

1. 강의 내용과 관련된 질문을 남겨주세요.
2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.
(자주 하는 질문 링크: https://bit.ly/3fX6ygx)
3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.
(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)

질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.
=========================================
[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예/아니오)
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오)
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오)

[질문 내용]
여기에 질문 내용을 남겨주세요.

 

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

2024-04-01T15:54:52.319+09:00 ERROR 11136 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initDb': Invocation of init method failed

. . .

Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : jpabook.jpashop.domain.Order.delivery -> jpabook.jpashop.domain.Delivery

. . .

Caused by: java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : jpabook.jpashop.domain.Order.delivery -> jpabook.jpashop.domain.Delivery

. . .

Caused by: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : jpabook.jpashop.domain.Order.delivery -> jpabook.jpashop.domain.Delivery

at org.hibernate.engine.spi.CascadingActions$8.noCascade(CascadingActions.java:372) ~[hibernate-core-6.4.4.Final.jar:6.4.4.Final]

at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:173) ~[hibernate-core-6.4.4.Final.jar:6.4.4.Final]

at org.hibernate.event.internal.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:161) ~[hibernate-core-6.4.4.Final.jar:6.4.4.Final]

at org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:144) ~[hibernate-core-6.4.4.Final.jar:6.4.4.Final]

at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:79) ~[hibernate-core-6.4.4.Final.jar:6.4.4.Final]

at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40) ~[hibernate-core-6.4.4.Final.jar:6.4.4.Final]

at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127) ~[hibernate-core-6.4.4.Final.jar:6.4.4.Final]

at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1403) ~[hibernate-core-6.4.4.Final.jar:6.4.4.Final]

... 44 common frames omitted

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.6/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : jpabook.jpashop.domain.Order.delivery -> jpabook.jpashop.domain.Delivery

Caused by: java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : jpabook.jpashop.domain.Order.delivery -> jpabook.jpashop.domain.Delivery

Caused by: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : jpabook.jpashop.domain.Order.delivery -> jpabook.jpashop.domain.Delivery

 

에러메시지가 위와 같이 떠서 구글에서 해결방법들을 찾아서 해봤는데 다 해결되지 않았습니다 ㅠㅠ 혹시 어떻게 해야할까요?

답변 1

답변을 작성해보세요.

2

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2024.04.01

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

질문자님의 상황과 아주 유사한 질문의 답변을 찾았습니다. 하단 내용은 질문자님이 경험하고 계신 ApplicationContext 시작 시 발생하는 오류TransientPropertyValueException 문제에 대한 해결책을 제공합니다.

1. 상품 주문시 에러가 발생합니다.

  • 핵심 내용: Order 객체 저장 전에 Delivery 객체를 먼저 저장하지 않아 발생하는 TransientPropertyValueException 오류 문제입니다. 해결 방법으로 Order 엔티티에 cascade 옵션을 추가하거나, Delivery를 먼저 저장한 후 Order 객체를 저장하시는 방법이 제시되었습니다.

2. 에러.. 도와주세요

  • 핵심 내용: org.hibernate.AnnotationException 오류는 @OneToOne 또는 @ManyToOne 관계에서 잘못된 엔티티를 참조하고 있기 때문에 발생합니다. 특히, OrderItem의 Order를 잘못 import한 경우 발생할 수 있는데, 정확히 jpabook.jpashop.domain.Order 엔티티를 참조하도록 수정이 필요합니다.

문제 해결을 위한 제안:

  • Cascade 옵션 확인: 질문자님이 겪고 계신 문제는 관계를 가진 엔티티 간 올바르게 저장되지 않아 발생하는 것 같습니다. Order와 Delivery 관계에 cascade 옵션을 사용해 해결할 수 있습니다.
  • 엔티티 참조 확인: 주어진 오류로 보아, 잘못된 클래스를 import하고 있지는 않은지 확인해 보시기 바랍니다. 특히 @OneToOne 또는 @ManyToOne 어노테이션을 사용할 때 정확한 엔티티를 참조하고 있는지 검토가 필요합니다.

이와 같은 문제는 주로 엔티티 간 관계 설정의 부정확함 또는 cascade 옵션 누락 등으로 인해 발생할 수 있으므로, 관련 설정을 세심하게 검토해 보시면 해결에 도움이 될 것입니다.

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

cascade를 다른 곳에 설정하고 있었네요
order 클래스에서 cascade를 설정하니 해결되었습니다.