inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발

Spring Data JPA를 이용한 초기 데이터 생성

테이블 생성 전 insert

556

김지언

작성한 질문수 2

1

안녕하세요. 강의 잘 듣고 있습니다.

data.sql 없을 땐 테이블 생성 되고 문제 없었는데

data.sql 파일을 만드니까 테이블 생성하기 전에 insert를 해서 에러가 나는 것 같습니다.

어떻게 해결하면 좋을까요.. 

 insert into user values(1, sysdate(), "eony", "asdf", "941010-2020200"); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USER" not found; SQL statement:

insert into user values(1, sysdate(), "eony", "asdf", "941010-2020200") [42102-200]

 Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/Users/eony/workspace/study/%ec%9d%b8%ed%94%84%eb%9f%b0%ea%b0%95%ec%9d%98/restful-web-service/target/classes/data.sql]: insert into user values(1, sysdate(), "eony", "asdf", "941010-2020200"); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USER" not found; SQL statement:

insert into user values(1, sysdate(), "eony", "asdf", "941010-2020200") [42102-200]

rest-api spring-boot

답변 4

4

ultimates

해당에러는 스프링부트 2.5버전부터 하이버네이트와 .sql 간의 순번에 의한 에러인듯합니다. 버전이올라가면서 .sql파일의 우선순위가 높아졌습니다. 아래와같이 설정해주시면됩니다.

defer-datasource-initialization: true

3

Dowon Lee

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

답변이 늦어 죄송합니다. 

위에 분이 답변을 먼저 주신것 같습니다. 관련 내용을 아래 게시물에서도 확인해 보실 수 있습니다. 

https://www.inflearn.com/questions/224708

감사합니다. 

2

Tae Won Choi

감사합니다!

1

Tae Won Choi

저도 같은 오류가 나네요.. 

JPA

0

62

1

jpa dependency를 추가하고 SecurityConfig클래스에서 오류가 납니다.

0

71

1

웹 브라우저 400 bad request

0

73

1

@Size는 되는데 @Past는 안 됩니다.

0

64

1

pdf 자료는 없나요?

0

76

2

locale 정보가 null 이면 무조건 messages_ko.properties이 호출 되는 문제

0

91

2

Swagger 강의, Unable to infer base url 이거 뜨시는 분들 도움되시라고

0

120

1

강의에서나온 화면 피피티

0

161

1

HelloWorldBean 관련 에러

0

189

2

Swagger API 3.x 오류..

0

223

1

java: variable message not initialized in the default constructor 에러는 어찌하면 좋을까요?

1

283

1

현재 GIT에 올리신 소스를 실행해봤습니다.

0

190

2

고양이 소리가 귀엽네요 !!

0

140

2

git에서 소스받고 실습중인데

0

120

1

post가 안되요

0

107

1

한국어 같은 경우 언어코드인 messages_ko.properties 로 생성하는게 더 좋지 않나요?

0

169

2

리턴타입으로서 EntityModel<User> 와 ResponseEntity질문

0

107

1

예외처리쪽 관련 질문있습니다.

0

161

2

엔티티가 바로 응답으로 나가도 되나요??

0

230

2

안녕하세여 Cannot invoke "co.kr.joneconsulting.resfulservice.repository.PostRepository.save(Object)" because "this.postRepository" is null

0

142

2

사용자 등록하고 나서 H2 에서 보면 신규 사용자의 password, ssn 이 null 로 되어 있습니다.

0

144

2

ApplictionContext 질문

0

196

2

롬북이 안먹히는것같아요

0

159

1

인텔리제이에서스프링부트 파일 실행하면

0

242

1