[Spring]JPA優先パラメータ
1)プロジェクトの作成
Vscodeを実行し、F 1-
create java project
-Maven
をクリックします.maven-archetype-quickstart
クリック-version1.4
パッケージ名:
dev.hibernate
プロジェクト名:
jpa
Select Destination Folder
クリックenter
Open
クリックすると新しいVscodeウィンドウが実行されます!App.Javaで
F5
をクリックし、端末でHello World
を出力して終了2) pom.xml設定
pom.xmlの
<properties>
:1.7から1.8に変更pom.xml
の<dependencies>
に追加<!-- H2 DB -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
</dependency>
<!-- JPA 구현체 Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.10.Final</version>
</dependency>
インストールがうまくいかなかったら.
端末
mvn -U clean install
に入力pom.右クリックxml
Update project
クリック👍 タグを表示して終了!
3)H 2データベースのインストール
https://www.h2database.com/html/main.html
[すべてダウンロード]をクリックします.
上部
Version 2.1.210
のPlatform-independent Zip
をクリックします.必要なファイルに解凍:
h2 폴더
作成h 2フォルダにファイルが作成されました!
bin
フォルダ—h2w
実行ファイアウォールがOKであれば、Web上にH 2コンソールが表示されます
연결
クリックこのページを開くと完成です!
C:\Users\wlswn
パス生成test.mv
というDB4) persistence.xmlの生成
main-フォルダ名:
resources
作成resources-フォルダ名:
META-INF
作成META-INF-ファイル名:
persistence.xml
生成<?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>
コードをpersistence.xml
に貼り付けます.戻るを使用して接続を解除するには
JDBC URL:
jdbc:h2:tcp://localhost/~/test
に変更し、연결
をクリックConnect
クリック5) persistence.xml補完コード
<?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="jpa"> <!-- 프로젝트 이름 -->
<properties>
<!-- property name -->
<!-- javax.persistence 로 시작하는 속성들 : JPA 표준 속성 -->
<!-- hibernate ~ : JPA의 구현체 중 하나인 hibernate의 전용 속성-->
<!-- DB와 연결하기 위한 필수 속성 -->
<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"/>
<!-- DB Dialect(방언) 설정 -->
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<!-- 옵션(선택) 속성 -->
<!-- hibernate의 실행 과정에서 console에 테이블 생성, DDL, DML 등 SQL문을 출력하도록 하는 설정 -->
<property name ="hibernate.show_sql" value ="true"/>
<!-- SQL 출력 상태 정렬 -->
<property name ="hibernate.format_sql" value ="true"/>
<!-- 주석문도 포함해서 출력하기 -->
<property name ="hibernate.use_sql_comments" value ="true"/>
<!-- ***(중요!!)*** 애플리케이션 실행 시 DB테이블을 자동으로 실행할 것인지?? -->
<!-- create : 기존에 테이블이 존재하면 삭제(drop) 후 새로 생성(create), DROP + CREATE -->
<!-- update : DB테이블과 Entity(객체)의 매핑(Mapping) 정보들 비교, 변경된 사항만 수정, 반영 -->
<property name ="hibernate.hbm2ddl.auto" value ="create"/>
</properties>
</persistence-unit>
</persistence>
Reference
この問題について([Spring]JPA優先パラメータ), 我々は、より多くの情報をここで見つけました https://velog.io/@dingdoooo/Spring-JPA-환경-설정テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol