Wednesday, January 7, 2015

How to Configure database credential in context.xml file and read it using Hibernate configuration file


Put your context.xml file in the META-INF directory



context.xml

<?xml version="1.0" encoding="UTF-8"?>
<context>
<Resource name="jdbc/dbresource" auth="Container"
        type="javax.sql.DataSource" username="imusername" password="impassword"
        driverClassName="oracle.jdbc.driver.OracleDriver"
        url="jdbc:oracle:thin:@//IP:1521/mydb"
        maxActive="10" maxIdle="4" />
</context>

Hibernate.cfg.xml

<?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>
        <!-- Database connection settings -->
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="hibernate.connection.datasource">java:/comp/env/jdbc/dbresource</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="show_sql">false</property>
<property name="format_sql">false</property>
<property name="use_sql_comments">false</property>
<property name="hibernate.jdbc.use_get_generated_keys">true</property>

<!-- Resource mapping -->
<mapping class="com.raj.UserData"/>
  </session-factory>

</hibernate-configuration>


Keep Visiting :)
Write your comment 

No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...