<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Re: Database password change during application is running in hibernate
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/padma818">Padmanabha Mishra</a> in <i>Beginner's Corner</i> - <a href="https://community.jboss.org/message/793967#793967">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Dear jaikiran,</p><p>Thanks for your reply.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>My config file:</p><p>xml version='1.0' encoding='UTF-8'?></p><p><!DOCTYPE hibernate-configuration PUBLIC</p><p>          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"</p><p><span>          "</span><a class="jive-link-external-small" href="http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" rel="nofollow" target="_blank">http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd</a><span>"></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><hibernate-configuration></p><p>    <session-factory></p><p>        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property></p><p>        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        <property name="hibernate.connection.username">hr</property></p><p>        <property name="hibernate.connection.password">hr</property></p><p>        <property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property></p><p>        <property name="dialect"></p><p>            org.hibernate.dialect.OracleDialect</p><p>        </property></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        <property name="show_sql">true</property></p><p>        <!-- <property name="hbm2ddl.auto">create</property>--></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        <mapping resource="Mybean.hbm.xml" /></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    </session-factory></p><p></hibernate-configuration></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>My Hibernate util class:</p><p>import org.hibernate.SessionFactory;</p><p>import org.hibernate.cfg.Configuration;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>public class HibernatePlug{</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    private static SessionFactory factory = getSessionFactory();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    public static synchronized SessionFactory getSessionFactory()</p><p>    {</p><p>            try {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                                Configuration cfg = new Configuration();</p><p>                                cfg.configure("hibernate.cfg.xml");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                                SessionFactory sessionFactory = cfg.buildSessionFactory();</p><p>                                System.out.println(" ----------   Factory Object Created  ------------");</p><p>                                return sessionFactory;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                  }             catch (Throwable ex) {</p><p>                                 System.err.println("Initial SessionFactory creation failed." + ex);</p><p>                                 throw new ExceptionInInitializerError(ex);</p><p>                  }</p><p>      }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    public static SessionFactory getFactory() {</p><p>        return factory;</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>For example to get records:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>public class MyOperations{</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    SessionFactory factory = HibernatePlug.getFactory();</p><p>    Session session = factory.openSession();</p><p>    Mybean p;</p><p>    List recList = null;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    public List retrieveRecords() {</p><p>        recList = (List<Mybean>) session.createQuery("from Mybean b").list();</p><p>        System.out.println("got size"+recList.size());</p><p>        return recList;</p><p>    }</p><p>}</p><p>Thanks</p><p>Padmanabha</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/793967#793967">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Beginner's Corner at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>