[jboss-user] [Beginner's Corner] - Re: Database password change during application is running in hibernate

Padmanabha Mishra do-not-reply at jboss.com
Thu Jan 24 02:52:49 EST 2013


Padmanabha Mishra [https://community.jboss.org/people/padma818] created the discussion

"Re: Database password change during application is running in hibernate"

To view the discussion, visit: https://community.jboss.org/message/793967#793967

--------------------------------------------------------------
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 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
[https://community.jboss.org/message/793967#793967]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130124/88c2288b/attachment.html 


More information about the jboss-user mailing list