Develope/DataBase

[JPA] Spring + MariaDB + JPA 환경셋팅

고로이 2021. 6. 23. 13:18
반응형

 

0. docker로 mariaDB 설치

  • sudo docker search maria
  • sudo docker pull mariadb:latest
  • sudo docker images

  • docker 이미지 실행 : sudo  docker run  --name mariadb -i -t -p 3306:3306 -e MYSQL_ROOT_PASSWORD=eunbi 
    • --name : 컨테이너 명
    • -p : 포트 포워딩
    • -e MYSQL_ROOT_PASSWORD : 초기 root 패스워드 지정
    • -v : Volume 데이터 저장 위치
  • docker exec -it mariadb /bin/bash

MariaDB [(none)]> create databases JPA_EB

MariaDB [(none)]> use JPA_EB

MariaDB [(none)]> create user 'eunbi'@localhost identified by 'eunbi123!';

MariaDB [(none)]> grant all privileges on *.* to eunbi@‘%’;

MariaDB [(none)]> grant all privileges on *.* to eunbi@localhost identified by 'eunbi123!’;

MariaDB [(none)]> flush privileges

 

 

JDK 1.8 or later

Gradle 4+ or Maven 3.2+

Spring Tool Suite (STS) or IntelliJ IDEA

 

1. 새 프로젝트 생성(Gradle 사용)

 

https://spring.io/guides/gs/accessing-data-jpa/

 

2. appendency 추가

 

build.gradle

plugins {

    id 'java'

    id 'org.springframework.boot' version '2.4.3'

    id 'io.spring.dependency-management' version '1.0.11.RELEASE'

}

 

group 'eunbi.jpa'

version '1.0'

 

repositories {

    mavenCentral()

}

 

dependencies {

       testCompile group: 'junit', name: 'junit', version: '4.12'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    testImplementation 'org.springframework.security:spring-security-test'

 

    //JPA

    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

    implementation 'org.springframework.boot:spring-boot-starter-security'

    implementation 'org.springframework.boot:spring-boot-starter-web'

 

    // MariaDB

    runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'

    compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.13'

 

    //lombok

    compileOnly 'org.projectlombok:lombok'

    annotationProcessor 'org.projectlombok:lombok'

 

    //slf4j

    compile 'org.slf4j:slf4j-api:1.7.5'

}

 

application.yml

spring:
datasource:
jpa-eb :
jdbcUrl: jdbc:mariadb://localhost:3306/JPA_EB
driver-class-name: org.mariadb.jdbc.Driver
username: eunbi
password: eunbi123!
jpa:
open-in-view: false
generate-ddl: true
show-sql: true
hibernate:
ddl-auto: update
# jpa.database-platform= org.hibernate.dialect.MySQL5InnoDBDialect
# jpa.properties.hibernate.format_sql= true


 

 

이후 그래들 리프레시

 

 

 

 

jpa-basic.zip
1.75MB

Unknown integral data type for ids : java.lang.String

=> hibernate에서 id 는 long값이다.

 

 

 

반응형

'Develope > DataBase' 카테고리의 다른 글

[JPA] 엔티티 매핑  (0) 2021.08.17
[JPA] 영속성 컨텍스트  (0) 2021.08.12
[JPA] 1-3. ORM 이란? JPA 소개  (0) 2021.05.30
[JPA] SQL을 직접 다룰 때 발생하는 문제점  (0) 2021.05.29
[JPA] JPA 현황 및 분석  (0) 2021.05.29