How and Where to add JNDI for Hibernate?

15,409

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>
Share:
15,409
bali208
Author by

bali208

Java/JEE application developer

Updated on June 06, 2022

Comments

  • bali208
    bali208 almost 2 years

    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.

  • bali208
    bali208 about 12 years
    Thank you... I dint know abt the hibernate.connection.datasource now where to add that?? You mean in the oracle-ds.xml ??? in which tag should i modify???
  • Ken Chan
    Ken Chan about 12 years
    hibernate.connection.datasource is for the hibernate configuration file which default file name is hibernate.cfg.xml