• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

insert 가 안됩니다...

22.07.31 21:16 작성 조회수 314

0

data.sql을 만들고 insert구문을 쓰면 Table "USERALL" not found 에러가 뜹니다

 

보다싶이 insert 구문을 쓰기 전까지는 테이블이 생성된 걸 h2-console에서 확인할 수 있었습니다 ㅠㅠ 그런데 data.sql만 생성하고 insert하려고 하면 갑자기 테이블이 없다고 뜨네요 .... 

yml 파일이고

spring:
jpa:
show-sql: true
hibernate:
ddl-auto: create
defer-datasource-initialization: true
messages:
basename: messages
mvc:
pathmatch:
matching-strategy: ant_path_matcher
#h2 console 활성화
h2:
console:
enabled: true
#원격접속 허용
settings:
web-allow-others: true
# 경로
path: /h2-console
#유일한 이름 생성 여부
datasource:
generate-unique-name: false
#url 경로
url: jdbc:h2:mem:testdb
#class 명칭
driver-class-name: org.h2.Driver

 

pom 파일입니다

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>runtime</scope> <!-- RUNTIME 에서만 실행 -->
</dependency>

 

답변 1

답변을 작성해보세요.

0

안녕하세요, 이도원입니다. 

Hibernate가 초기화 되기 전에 data.sql이 실행되어서 테이블이 존재하지 않는다는 오류가 발생한 것 같습니다. data.sql 파일과 같은 위치에 schema.sql 파일을 생성한 다음, create table로 테이블을 생성하시거나, application.yml 파일에 아래와 같은 설정으로 테이블을 생성할 수도 있습니다. 

spring.jpa.defer-datasource-initialization: true

감사합니다.