일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 호이스팅
- analytics4
- group by
- github
- 추상클래스
- DBMS
- Python
- rsync
- JPA
- 차이점
- IntelliJ
- MariaDB
- java
- MongoDB
- SQL
- PostgreSQL
- oracle
- spring
- 오블완
- 자바
- git
- 리눅스
- mssql
- docker
- 티스토리챌린지
- 트랜잭션
- mysql
- 명령어
- Linux
- Javascript
- Today
- Total
hanker
Spring boot - application.properties MySQL DB 설정 본문
pom.xml
<!-- mysql jdbc -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
# MySQL8 설정
spring.datasource.url=jdbc:mysql://localhost:3306/스키마명?useSSL=false&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=아이디
spring.datasource.password=비밀번호
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 콘솔에 SQL 출력 여부
spring.jpa.show-sql=true
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
# hibernate 설정
spring.jpa.database=mysql
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.generate-ddl=false
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
설정을 자세히 살펴보면
spring.jpa.database=mysql
- mysql 사용하겠다.
spring.jpa.hibernate.ddl-auto=none
- 서버를 실행할 때마다 DB 초기화하기
- none : DB구조는 변경되지 않음
- update : 변경된 스키마만 적용
- create : 시작될 때만 drop하고 다시 생성
- create-drop : 시작과 종료에서 모두 drop
(hibernate 4)
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
(hibernate 5)
spring.jpa.hibernate.naming.implicit-strategy
=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
spring.jpa.hibernate.naming.physical-strategy
=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
- 설정을 하지 않으면 CamelCase to UnderScore가 자동으로 Default값으로 설정
spring.jpa.generate-ddl=false
- true일 경우 해당 데이터를 근거로 서버 시작 지점에 DDL문을 생성하여 DB에 적용
spring.jpa.properties.hibernate.format_sql=true
- SQL문을 로그에 출력
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
- true : LazyInitializationException에러 방지
참고.
www.baeldung.com/hibernate-lazy-loading-workaround
Quick Guide to Hibernate enable_lazy_load_no_trans Property | Baeldung
Lazy loading can reduce unnecessary database traffic, but it requires all lazy-loaded object navigation within the session. Hibernate provides a workaround.
www.baeldung.com
'SPRING' 카테고리의 다른 글
Spring boot - jsp 사용 (0) | 2021.01.12 |
---|---|
Spring boot - jsonView 사용 (0) | 2021.01.12 |
Spring - MySQL 연동 테스트 (0) | 2021.01.08 |
SPRING - 여러줄 주석방법 (0) | 2020.12.04 |
SPRING - java.sql.Date 와 java.util.Date의 차이 (0) | 2020.11.05 |