Discussion:
[jboss-user] [Beginner's Corner] - Database password change during application is running in hibernate
Padmanabha Mishra
2013-01-21 12:03:38 UTC
Permalink
Padmanabha Mishra [https://community.jboss.org/people/padma818] created the discussion

"Database password change during application is running in hibernate"

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

--------------------------------------------------------------
HI all,

I have a question here.
I have a web application where database is accessed through Hibernate.
While the application is running, Database user password is changed.But there is no effect on the application. Through hibernate we are able to access database with old configuration untill the container(tomcat) is restarted.
So can any body please tell me that is this the way hibernate works?
Or can we put hibernate in application level so that in beetween if database user password is changed, then it should throw exception in application while accessing to database.

Please guide me.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793216#793216]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Peter Johnson
2013-01-21 15:47:48 UTC
Permalink
Peter Johnson [https://community.jboss.org/people/peterj] created the discussion

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

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

--------------------------------------------------------------
This is standard behavior for anything that requires a password to sign in - a change in the password doesn't matter until you have to sign in again. Thus once Hibernate connects to the database, as long as it maintains that connection any password change will not affect anthing until you restart your app which will cause Hibernate to attempt to sign in again, at whihc point it will fail due to the changes password (unless you also update the Hibernate connection settings).
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793273#793273]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Padmanabha Mishra
2013-01-23 04:52:44 UTC
Permalink
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/793646#793646

--------------------------------------------------------------
Dear Peter,

Thanks for your quick reply. Its really helpfull information.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793646#793646]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Padmanabha Mishra
2013-01-24 06:56:14 UTC
Permalink
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/793947#793947

--------------------------------------------------------------
Dear Peter,

In my web application, I am accessing oracle database through hibernate. When i restart my database(Oracle) service while my application is running,after that when i am accessing my application its throwing sql exception.
After I reload the application its working fine. When I check database sessions there is no session which means its unable to create the session agin.
I could not understand what is the problem?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793947#793947]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
jaikiran pai
2013-01-24 07:12:10 UTC
Permalink
jaikiran pai [https://community.jboss.org/people/jaikiran] created the discussion

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

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

--------------------------------------------------------------
I assume you are using a datasource in your hibernate configuration. What does your datasource configuration (-ds.xml) look like? And please post the entire exception stacktrace that you see when Hibernate fails to reconnect after the DB is restarted.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793950#793950]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Padmanabha Mishra
2013-01-24 07:52:49 UTC
Permalink
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]
Loading...