일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- Spring Boot
- REACT
- Jenkins Pipeline
- Docker
- vue.js
- error
- MySQL
- gradle
- Jenkins
- nginx
- docker network
- IntelliJ
- subnetmask
- jenkins 설치
- spring
- Linux
- 리눅스
- grpc
- jenkins install
- java
- JavaScript
- jenkins jdk
- jenkins github
- grafana
- 리액트
- jenkins github 연동
- CI/CD
- jpa
- MongoDB
- jenkins maven
- Today
- Total
뭐든 즐기면서 ;)
Spring Boot(Gradle) + MySQL + JPA(Hibernate) [2] - Spring Data JPA 설정 1 본문
Spring Boot(Gradle) + MySQL + JPA(Hibernate) [2] - Spring Data JPA 설정 1
Tada.*+ 2021. 10. 25. 19:35참고 : https://velog.io/@chyin370/ToyProject-JPAHibernate-%EC%A0%81%EC%9A%A9%ED%95%98%EA%B8%B0
1. application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/study_db?autoReconnect=true
spring.datasource.username=root
spring.datasource.password=data~secret!
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database=mysql
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.open-in-view=false
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.format_sql=true
logging.level.web=DEBUG
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.BasicBinder=TRACE
# dummy data
spring.jpa.properties.hibernate.hbm2ddl.import_files=classpath:sql/init-import.sql
spring.jpa.properties.hibernate.hbm2ddl.import_files_sql_extractor=org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor
2. Entity 생성
@Enumerated 어노테이션 부가 설명 참고 : https://lng1982.tistory.com/280
* error 발생 : 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: Attribute [com.study.jpa.entity.User.gender] was annotated as enumerated, but its java type is not an enum [java.lang.String]
해결 방법 ↓ ↓ ↓ ↓
Enum class로 생성해 준다.
3. SQL 작성
application.properties에 작성한 spring.jpa.properties.hibernate.hbm2ddl.import_files 에 대응되는 sql파일
* error 발생 : org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "INSERT INTO user (email, ....................
Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'cellPhone' in 'field list'
해결 방법 : Entity에 카멜 표기법으로 선언한 변수 칼럼을 스네이크 표기법으로 변경하여 sql 작성해야 함.
* error 또 발생 : Caused by: java.sql.SQLException: Column count doesn't match value count at row 1
해결 방법 : insert 문에 칼럼과 value 작성 수가 같지 않음. (cell_phone value 입력 안 함..)
4. Spring Boot 실행
5. DB Insert 값 확인
'BACK > Spring Boot & JPA' 카테고리의 다른 글
Spring Security 기본 설정 (0) | 2023.04.28 |
---|---|
Spring Boot + Gradle Multi Module (0) | 2022.11.18 |
JPA persistence.xml / JPA DB설정 (0) | 2021.11.27 |
Spring Boot(Gradle) + MySQL + JPA(Hibernate) [3] - Spring Data JPA 설정 2 (0) | 2021.10.27 |
Spring Boot(Gradle) + MySQL + JPA(Hibernate) [1] - Spring Boot 설정 (0) | 2021.10.24 |