4.3. Hibernate 接続プロパティーの設定

Tomcat プールからの接続を使用するように Hibernate を設定します。Hibernate API を直接使用する場合は、hibernate.cfg.xml と似た設定を使用します。

手順

  1. デプロイメントの /WEB-INF/classes/META-INF/persistence.xml ファイルを開いて編集します。
  2. 以下の例のように、Hibernate が Tomcat から接続をどのように消費するかを設定します。

    <persistence version="1.0"
      xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    
      <persistence-unit name="dswebapp">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
          <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
          <property name="hibernate.connection.datasource" value="java:comp/env/jdbc/DsWebAppDB"/>
        </properties>
      </persistence-unit>
    </persistence>