정리노트/JPA
자바 ORM 표준 JPA 프로그래밍 - 기본편 01
컵라면만두세트
2022. 4. 26. 14:14
프로젝트 생성
설정
- JAVA → jdk 1.8
- MAVEN 기반으로 진행
- H2 DATA BASE활용
POM.xml → hibernate 관련 설정 의존성 주입
- resources → META-INF → persistence.xml 파일에서 다양한 JPA 방언을 주입할 수 있음, 그와 관련된 url, user, password 정보를 읽어오고 진행
애플리케이션 개발
<?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=""/>
<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>
- 데이터 방언
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
- ORACLE : org.hibernate.dialect.MySQL5InnoDBDialect
- MYSQL: org.hibernate.dialect.Oracle10gDialect
- H2 : org.hibernate.dialect.H2Dialect
- 다양한 데이터베이스 방언 지원