you can use this config in your apps (~.cfg.xml) to check the DataSource by JNDI
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dataSource">java:comp/env/jdbc/JNDI_Name</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property><!-- your dialect-->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<mapping resource="mapping/xxx.hbm.xml"/>
<mapping resource="mapping/yyy.hbm.xml"/>
</session-factory>
</hibernate-configuration>
If you use Spring xml conf, create an xml file for Datasource && sessionFactory && transactionManager:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<tx:annotation-driven />
<context:component-scan base-package="x.y.z.*" />
<context:annotation-config />
<import resource="classpath:~/~.cfg.xml" />
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/Your_JNDI_Name"/>
</bean>
<!-- OR ORM HIBERNATE PART -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:~/~.cfg.xml</value>
</property>
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory">
</bean>
<!-- Declaration of DOA beans Hibernate -->
<bean id="myDao" class="class_dao">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
I hope that's helpful for you