gpt4 book ai didi

hibernate - 如何以及在何处为 Hibernate 添加 JNDI?

转载 作者:行者123 更新时间:2023-12-04 05:55:46 25 4
gpt4 key购买 nike

我需要代码来添加 JNDI 名称以在 hibernate 中实现连接池。
我已将 Jboss 服务器中的连接池配置为 JNDI 名称为“EmployeeDB”

如何在 hibernate.cfg.xml 中配置??

如果我使用的是 Hibernate 4 Final release,请给我 hibernate.cfg.xml 的代码。

最佳答案

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 - 如何以及在何处为 Hibernate 添加 JNDI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9677075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com