【发布时间】:2012-03-13 01:15:19
【问题描述】:
我需要代码来添加 JNDI 名称以在休眠中实现连接池。 我已将 Jboss 服务器中的连接池配置为 JNDI 名称为“EmployeeDB”
在hibernate.cfg.xml中如何配置??
如果我使用的是 Hibernate 4 Final 版本,请给我 hibernate.cfg.xml 的代码。
【问题讨论】:
标签: hibernate jndi connection-pooling
我需要代码来添加 JNDI 名称以在休眠中实现连接池。 我已将 Jboss 服务器中的连接池配置为 JNDI 名称为“EmployeeDB”
在hibernate.cfg.xml中如何配置??
如果我使用的是 Hibernate 4 Final 版本,请给我 hibernate.cfg.xml 的代码。
【问题讨论】:
标签: hibernate jndi connection-pooling
Jboss 服务器中配置的数据源 JDNI 名称由属性hibernate.connection.datasource 指定。
基本的hibernate.cfg.xml 应该是这样的:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.datasource">java:comp/env/jdbc/EmployeeDB</property>
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Mapped annotated entity-->
<mapping class="org.hibernate.tutorial.domain.Event"/>
</session-factory>
</hibernate-configuration>
【讨论】:
hibernate.connection.datasource 用于休眠配置文件,默认文件名为hibernate.cfg.xml