JPA 설정 추가 - persistence.xml

Mina Park·2022년 8월 21일
0
post-thumbnail
  1. jpa 기본설정
  • 위치: main/resource/META-INF/persistence.xml
    • 파일 위치 중요!!
  • javax.persistence로 시작:JPA 표준 속성
  • hibernate로 시작: 하이버네이트 전용 속성
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
             xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
    <persistence-unit name="hello">
        <properties>
            <!-- 필수 속성 -->
            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
            <property name="javax.persistence.jdbc.user" value="sa"/>
            <property name="javax.persistence.jdbc.password" value="1111"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:h2:tcp://localhost/~/test"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
            <!-- 옵션 -->
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.use_sql_comments" value="true"/>
            <!--<property name="hibernate.hbm2ddl.auto" value="create" />-->
        </properties>
    </persistence-unit>
</persistence>
  1. database dialect
  • jpa 는 특정 데이터베이스에 종속 X
  • 방언이란? SQL 표준을 지키지 않는 특정 데이터베이스만의 고유 기능
    • 각 데이터베이스가 제공하는 SQL 문법과 함수는 조금씩 다름
    • Ex) 페이징: MySQL - LIMIT, Oracle - ROWNUM
  • hibernate.dialect에 자신이 사용할 속성 지정 가능

    H2 : org.hibernate.dialect.H2Dialect
    • Oracle 10g : org.hibernate.dialect.Oracle10gDialect
    • MySQL : org.hibernate.dialect.MySQL5InnoDBDialect

스프링 부트 사용시, application.yml/application.properties 만 작성

  • application.yml / application.propertie : 어플리케이션 설정정보
  • persistence.xml: jpa 설정정보

0개의 댓글