이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 5. Configuring Hibernate for JBoss Web Server


Hibernate Object/Relational Mapping (ORM) is an object-relational mapping framework that you can use to connect JBoss Web Server to Java database connectivity (JDBC) datasources. You can use Hibernate ORM with JBoss Web Server when you want to store your application data in a relational database.

5.1. Installing Hibernate ORM

You can install Hibernate ORM on all platforms that JBoss Web Server supports. You can obtain the Hibernate JAR files in either of two ways:

Note

In a future release, Red Hat will remove the Hibernate JAR files from jboss-web-server-X.X.x-maven-repository.zip. In the JBoss Web Server 5.7 release, Red Hat continues to provide Hibernate JAR files in jboss-web-server-5.7.0-maven-repository.zip, but Red Hat does not provide any further updates to these JAR files except for any possible security fixes.

In JBoss Web Server 5.7 and future versions, Red Hat will continue to provide and maintain Hibernate JAR files in the Red Hat hosted Maven repository at https://maven.repository.redhat.com/ga/.

Prerequisites

  • You have configured your project to use either of the following Maven repositories:

Procedure

  1. Depending on the Maven repository you want to use, get the Hibernate JAR files from either jboss-web-server-X.X.x-maven-repository.zip or https://maven.repository.redhat.com/ga/.
  2. Add the Hibernate JAR files to your deployment WAR file.

5.2. Configuring JDBC connection pools

Apache Tomcat provides a default connection pooling mechanism for JDBC datasources. You can configure JDBC connection pools by updating settings in the /META-INF/context.xml file for your JBoss Web Server deployment.

Procedure

  1. Open the /META-INF/context.xml file.
  2. Modify the JDBC connection pools that are available to applications.

    For example:

    <Context>
      <Resource
        name="jdbc/DsWebAppDB"
        auth="Container"
        type="javax.sql.DataSource"
        username="sa"
        password=""
        driverClassName="org.h2.Driver"
        url="jdbc:h2:mem:target/test/db/h2/hibernate"
        maxActive="8"
        maxIdle="4"/>
    </Context>
    Copy to Clipboard Toggle word wrap

5.3. Configuring Hibernate connection properties

You can configure Hibernate to use JDBC connections from the Tomcat pool, by updating settings in the /WEB-INF/classes/META-INF/persistence.xml file for your JBoss Web Server deployment.

Note

If you want to use the Hibernate API directly, use a similar configuration to the hibernate.cfg.xml file.

Procedure

  1. Open the /WEB-INF/classes/META-INF/persistence.xml file.
  2. Configure Hibernate to consume connections from Tomcat.

    For example:

    <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>
    Copy to Clipboard Toggle word wrap

5.4. Adding JDBC data sources

You can configure Tomcat to consume JDBC data sources, by updating settings in the /WEB-INF/web.xml file for your JBoss Web Server deployment.

Procedure

  1. Open the /WEB-INF/web.xml file.
  2. Configure JDBC datasources with the resource-env-ref element.

    For example:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
     <resource-env-ref>
      <resource-env-ref-name>jdbc/DsWebAppDB</resource-env-ref-name>
      <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
     </resource-env-ref>
    </web-app>
    Copy to Clipboard Toggle word wrap
    Note

    The preceding example uses a a jdbc/DsWebAppDB data source.

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat