5.3. 配置 Hibernate 连接属性
您可以通过更新 JBoss Web 服务器部署的 /WEB-INF/classes/META-INF/persistence.xml 文件中的设置,将 Hibernate 配置为使用 Tomcat 池中的 JDBC 连接。
注意
如果要直接使用 Hibernate API,请使用与 hibernate.cfg.xml 文件类似的配置。
步骤
-
打开
/WEB-INF/classes/META-INF/persistence.xml文件。 配置 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>