显然,您做对了。但是,这里列出了您需要的东西以及正在运行的应用程序中的示例:
1)meta-INF中的context.xml文件,指定您的数据源:
<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>
2)web.xml告诉容器您正在使用此资源:
<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>
3)使用数据源的hibernate配置。在这种情况下,它是一个
persistence.xml,但在
hibernate.cfg.xml
<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>



