How and Where to add JNDI for Hibernate?

匆匆过客 提交于 2019-12-04 19:43:44

问题


I need the code to add JNDI name to achive connection pooling in hibernate. I have configured the connetion pooling in Jboss server with the JNDI name as "EmployeeDB"

How to configure it in hibernate.cfg.xml ??

Plez give me the code for hibernate.cfg.xml if i am using Hibernate 4 Final release.


回答1:


The datasource JDNI name configured in the Jboss server is specified by the properties hibernate.connection.datasource.

The basic hibernate.cfg.xml should look like :

<?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>


来源:https://stackoverflow.com/questions/9677075/how-and-where-to-add-jndi-for-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!