5 Replies Latest reply on Jan 24, 2013 3:03 AM by Padmanabha Mishra

    Database password change during application is running in hibernate

    Padmanabha Mishra Newbie

      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.

        • 1. Re: Database password change during application is running in hibernate
          Peter Johnson Master

          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).

           

          One thing you might be able to do - restart the database. That should force Hibernate to reconnect which will cause a password failure.

          • 2. Re: Database password change during application is running in hibernate
            Padmanabha Mishra Newbie

            Dear Peter,

             

            Thanks for your quick reply. Its really helpfull information.

            • 3. Re: Database password change during application is running in hibernate
              Padmanabha Mishra Newbie

              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?

              • 4. Re: Database password change during application is running in hibernate
                jaikiran pai Master

                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.

                • 5. Re: Database password change during application is running in hibernate
                  Padmanabha Mishra Newbie

                  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;

                      }

                  }

                  stsch trace:

                  Jan 24, 2013 1:32:32 PM org.apache.catalina.core.StandardWrapperValve invoke

                  SEVERE: Servlet.service() for servlet default threw exception

                  java.sql.SQLException: No more data to read from socket

                      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)

                      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)

                      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207)

                      at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1117)

                      at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1069)

                      at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:477)

                      at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:215)

                      at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:798)

                      at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1038)

                      at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:838)

                      at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1131)

                      at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3284)

                      at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3328)

                      at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)

                      at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)

                      at org.hibernate.loader.Loader.doQuery(Loader.java:662)

                      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)

                      at org.hibernate.loader.Loader.doList(Loader.java:2211)

                      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)

                      at org.hibernate.loader.Loader.list(Loader.java:2090)

                      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)

                      at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)

                      at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)

                      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)

                      at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)

                      at java4s.MyOperations.retrieveRecords(MyOperations.java:24)

                      at java4s.Java4sController.getRecords(Java4sController.java:55)

                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

                      at java.lang.reflect.Method.invoke(Unknown Source)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)

                      at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)

                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)

                      at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)

                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)

                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)

                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

                      at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

                      at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

                      at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)

                      at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)

                      at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)

                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)

                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)

                      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

                      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)

                      at java.lang.Thread.run(Unknown Source)

                  Thanks

                  Padmanabha