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.
Using hibernate in web application is very easy, all we need is to configure DataSource properties in hibernate configuration file. First of all we need to setup test database and JNDI DataSource in tomcat container.
To use JDBC in a Spring Boot application, you can define a Liberty dataSource in the server. xml, identically to a Java EE application. The data source that is defined in server. xml can be looked up by JNDI by the jndiName attribute in the dataSource element.
A JNDI DataSource object is a file that contains the configuration details necessary to connect to a database. The DataSource object must be registered on a JNDI server, where it is identified using a JNDI name. You can register your DataSource object directly on your application server via its JNDI service.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With