2020. 5. 5. 00:32ㆍSPRING/Spring Data JPA
1. JPA, DB 라이브러리 메이븐 등록
1) pom.xml 수정
spring-boot-starter 를 spring-boot-starter-data-jpa 로 변경
이 프로젝트에서는 postgresql을 사용하였으므로 postgresql 라이브러리 등록
2. application.properties DB설정
spring.datasource.url=jdbc:postgresql://localhost:5432/springdata
spring.datasource.username=user
spring.datasource.password=pass
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
logging.level.org.hibernate.type.descriptor.sql=trace
① spring.datasource.url=DB경로
② spring.datasource.username=DB아이디
③ spring.datasource.password=DB패스워드
④ spring.jpa.hibernate.ddl-auto=DB테이블 다루는 방식
create : 테이블을 매번 새로 만듬. 있던 것도 없애고 새로 만든다.
update : 테이블이 존재할 경우 새롭게 데이터를 추가한다.
없는 경우는 새로 만들어주기는 하지만, 기존에 컬럼이 존재하는 경우 같은 이름의 다른 조건(크기, 타입)으로는
신규생성이 안되며, 기존 컬럼의 삭제 또한 불가능하다.
validate : 테이블 생성, 컬럼 추가 등을 해주지 않는다. 없는 테이블이나 없는 컬럼에 값을 넣으려고 하면 오류를 뱉어낸다.
⑤ spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
ture일 경우, createClob() 메서드 생성과 관련된 오류출력이 되지 않도록 한다. 오류메세지를 보기 싫은경우 설정.
⑥ spring.jpa.show-sql=true
true일 경우, 사용된 sql문을 console에 출력하여 볼 수 있도록 설정
⑦ spring.jpa.properties.hibernate.format_sql=true
true일 경우, 사용된 sql문을 console에서 정리된 상태로 깔끔하게 보여주도록 설정
⑧ spring.jpa.properties.hibernate.use_sql_comments=true
true일 경우, sql 관련된 주석이 함께 console에 출력된다.
⑨ logging.level.org.hibernate.type.descriptor.sql=trace
logging 레벨을 trace로 설정하면, 쿼리의 ?에 실제 들어간 입력값(파라미터)를 console창에 출력 가능하다.
'SPRING > Spring Data JPA' 카테고리의 다른 글
[Spring Data JPA] Repository 생성 (0) | 2019.10.08 |
---|---|
[Spring Data JPA] Cascade (0) | 2019.10.05 |
[Spring Data JPA] annotation(어노테이션) (0) | 2019.09.29 |