728x90
반응형
728x90
반응형
728x90
반응형

일반적으로 해당 에러는 사용되는 외래키가 오타, 문법, 외래키가 기본키인지 라고 한다.

 

https://onlyfor-me-blog.tistory.com/154

 

[MySQL] Error 1215: Cannot add foreign key constraint 에러 해결

참고한 사이트 : https://118k.tistory.com/145 [MySQL] Error Code: 1215. Cannot add foreign key constraint Error Code: 1215. Cannot add foreign key constraint MySQL 에서 외부키를 생성하는 중 오류가 발..

onlyfor-me-blog.tistory.com

 

 

근데 모델로 만든 스크립트라 오타나 문법이 있을리는 없는데?

그래서 이상해서 모델의 관계를 끊었다가 다시 이어보니 외래키가 두개가 들어온다.  
기본키가 복합키로 두개 이상인데 한개만 쿼리문에 있을 경우로 3번째 문제였다.
(중간에 기본키 수정이 있었다.)

728x90
반응형
728x90
반응형

원인 : jpa의 Entity 클래스에서 @Id를 사용하지 않아 발생

해당되는 테이블은 기본키가 없기 때문에 적용하지 않았으나, jpa 규칙상 Entity에 @Id가 필수이므로 어노테이션을 추가하여 수정했다.

실제 DB상에서 기본키인가 여부는 관계가 없으나, Entity의 @Id 어노테이션으로 인하여 기본키를 지정한 것과 동일한 효과를 갖는다.

 

* 참고정보 : 링크

 

* 아래는 에러 메시지

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: packageName.core.model.entity.EntityClassName

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1153)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:907)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:582)

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)

at packageName.BookKeepingApplication.main(BookKeepingApplication.java:10)

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: packageName.core.model.entity.EntityClassName

at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:266)

at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211)

at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:785)

at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:248)

at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:239)

at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:282)

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1224)

at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1255)

at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58)

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409)

at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396)

at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782)

... 17 common frames omitted

 

 

728x90
반응형

+ Recent posts