JBoss Community

Re: Database password change during application is running in hibernate

created by Padmanabha Mishra in Beginner's Corner - View the full discussion

Dear jaikiran,

Thanks for your reply.

 

My config file:

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="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>

 

        <property name="hibernate.connection.username">hr</property>

        <property name="hibernate.connection.password">hr</property>

        <property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>

        <property name="dialect">

            org.hibernate.dialect.OracleDialect

        </property>

 

        <property name="show_sql">true</property>

        <!-- <property name="hbm2ddl.auto">create</property>-->

 

 

        <mapping resource="Mybean.hbm.xml" />

 

 

    </session-factory>

</hibernate-configuration>

 

My Hibernate util class:

import org.hibernate.SessionFactory;

import org.hibernate.cfg.Configuration;

 

public class HibernatePlug{

 

    private static SessionFactory factory = getSessionFactory();

 

    public static synchronized SessionFactory getSessionFactory()

    {

            try {

 

                                Configuration cfg = new Configuration();

                                cfg.configure("hibernate.cfg.xml");

 

                                SessionFactory sessionFactory = cfg.buildSessionFactory();

                                System.out.println(" ----------   Factory Object Created  ------------");

                                return sessionFactory;

 

 

                  }             catch (Throwable ex) {

                                 System.err.println("Initial SessionFactory creation failed." + ex);

                                 throw new ExceptionInInitializerError(ex);

                  }

      }

 

    public static SessionFactory getFactory() {

        return factory;

    }

 

}

 

For example to get records:

 

public class MyOperations{

 

    SessionFactory factory = HibernatePlug.getFactory();

    Session session = factory.openSession();

    Mybean p;

    List recList = null;

 

    public List retrieveRecords() {

        recList = (List<Mybean>) session.createQuery("from Mybean b").list();

        System.out.println("got size"+recList.size());

        return recList;

    }

}

Thanks

Padmanabha

Reply to this message by going to Community

Start a new discussion in Beginner's Corner at Community