⚙ persistence.xml 설정

JPA의 어노테이션 패키지는 javax.persistence이다.

JPA는 persistence.xml을 사용해서 필요한 설정 정보를 관리한다.META-INF/persistence.xml 클래스 패스 경로에 있으면 JPA가 인식한다.

<persistence xmlns="<http://xmlns.jcp.org/xml/ns/persistence>" version="2.1">    <persistence-unit name="jpabook">        <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.id.new_generator_mappings" value="true"/>        </properties>    </persistence-unit></persistence>

설정 파일은 persistence로 시작한다. xml 네임스페이스와 사용할 버전 지정

<persistence xmlns="<http://xmlns.jcp.org/xml/ns/persistence>" version="2.1">

JPA 설정은 영속성 유닛(persistence-unit)부터 시작하는데 일반적으로 연결할 데이터베이스당 하나의 영속성 유닛을 등록한다. 그리고 고유한 이름을 부여해야 한다. <persistence-unit name="jpabook">

엔티티 클래스를 자동으로 인식하지 못할 경우 엔티티 클래스 지정

<class>jpabook.startMember</class>

속성 값 설명