-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Configuration.createSessionFactory never throws exception
PostPosted: Sun Sep 16, 2007 3:42 pm 
Newbie

Joined: Sun Sep 16, 2007 3:29 pm
Posts: 4
Hi,

I have some code Hibernate code that I've inherited from from someone else. Because I inherited it, I admit that I don't know the code nor hibernate very well. FWIW, I didn't see anything in the FAQ that addresses this.

We are having a problem in that when the password is wrong in our hibernate.jcfg.xml file, our DAOs try to connect to Oracle over and over again, until eventually Oracle locks the user. So then even users with the correct password in hibernate.jcfg.xml can't get it.

The bigger issue is that all of this occurs silently. I would like to see Configuration.buildSessionFactory() to throw an exception if there is an error at connect time. However, the above calls returns (albeit more slowly) silently without reporting error to the program nor the logs.

I'm sure the oracle JDBC driver is throwing an exception; but I don't know what's happening to it. It sure is with a simpler JDBC-only program with the same parameters.

I.e., I put a username that doesn't exist in the hibernate.jcfg.xml file, and neither an Exception nor an Error is thrown fro Configuration.buildSessionFactory(). Same with password being wrong; but that locks out the rest of the developers.

Is there a configuration option that I'm forgetting to set? Should I just turn off lazy connections (if so, how? All the docs I find talk about how to turn it *on*.) Any other tips -- including URLs to RTFM -- are welcome.

Thank you,
Brian Shelden


Is this a configuration

Hibernate version: 3.1

Mapping documents:

Not getting that far.

Code between sessionFactory.openSession() and session.close():

Not getting that far.

Full stack trace of any exception that occurs:

None (this is the problem.)

Name and version of the database you are using:

Oracle 10.2.0.3

The generated SQL (show_sql=true):

Not getting that far.

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 9:28 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 7:29 am
Posts: 36
It certainly does....

Code:
Caused by: java.sql.SQLException: ORA-01017: invalid username/password; logon denied

   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
   at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
   at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:283)
   at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:278)
   at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:790)
   at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:362)
   at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:420)
   at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
   at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
   at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
   at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
   ... 14 more


You need to catch the exception....

Can you post the Hibernate code???


Top
 Profile  
 
 Post subject: Attached code snippet
PostPosted: Tue Sep 18, 2007 10:24 am 
Newbie

Joined: Sun Sep 16, 2007 3:29 pm
Posts: 4
I added the catch for error recently; no change.

Code:
import org.hibernate.cfg.*;
import org.hibernate.*;



class OracleDAOFactory {
    //[...]
    //Hibernate Configuration object.
    private static Configuration m_configuration;

     
  private OracleDAOFactory() throws DAOException
  {
    //Explcitly call super constructor
    super();   
    System.out.println("BS: OracleDAOFactory() private constructor");

   
    //Create a new Hibernate Configuration object
    m_configuration = new Configuration();

    //If the configuration can't be created, throw an exception.
    if(m_configuration == null)
    {
      throw new DAOException("Configuration is null.");
    }
     
    //Configure the configuration. Note that this is where all the
    //various configuration files are read in.
    try
    {
      m_configuration.configure(CONFIG_FILE_NAME);
     
      //Set up the database connection parameters appropriately.
      configureDatabaseForEnvironment(m_configuration,
                                      CommonFunctions.getEnvironment());
    }
    catch(HibernateException h)
    {
      throw new
   DAOException("Configuration of Hibernate caused exception." + h );
    }
   
    //Create a Hibernate session factory.
    try
    {
      System.out.println("BS: pre-buildSessionFactory()");

      m_factory = m_configuration.buildSessionFactory();

      System.out.println("BS: post-buildSessionFactory()");
    }
    catch(Exception h)
    {
      throw new
   DAOException( "Exception caught on call to buildSessionFactory: " + h);
    }
    catch (Error e)
    {
   throw new DAOException("Error caught on call to buildSessionFactory"
                + e);
    }
   

   
    //Keep track of the singelton instance
    m_instance = this;
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 1:41 pm 
Beginner
Beginner

Joined: Fri Sep 08, 2006 7:29 am
Posts: 36
Can you please try this.....

Code:
private OracleDAOFactory() throws DAOException {
      m_configuration = new Configuration();

      // Configure the configuration. Note that this is where all the
      // various configuration files are read in.
      try {
         m_configuration.configure(CONFIG_FILE_NAME);

         // Set up the database connection parameters appropriately.
         configureDatabaseForEnvironment(m_configuration, CommonFunctions.getEnvironment());
      } catch (Exception h) {
         h.printStackTrace();
      }

      // Create a Hibernate session factory.
      try {
         System.out.println("BS: pre-buildSessionFactory()");

         m_factory = m_configuration.buildSessionFactory();

         System.out.println("BS: post-buildSessionFactory()");
      } catch (Exception h) {
         h.printStackTrace();
      }
      
      // Keep track of the singelton instance
      m_instance = this;
   }


I have removed a few lines....

Let me know what u get...

Shardul.


Top
 Profile  
 
 Post subject: Still no exception
PostPosted: Tue Oct 02, 2007 1:21 pm 
Newbie

Joined: Sun Sep 16, 2007 3:29 pm
Posts: 4
I pasted in your code (changing the debug println()s to have your initials, not mine):
Code:
  /** from the hibernate forums:
   * http://forum.hibernate.org/viewtopic.php?t=979553&highlight=
   *
   */
  private OracleDAOFactory() throws DAOException {
      m_configuration = new Configuration();

      // Configure the configuration. Note that this is where all the
      // various configuration files are read in.
      try {
         m_configuration.configure(CONFIG_FILE_NAME);

         // Set up the database connection parameters appropriately.
         configureDatabaseForEnvironment(m_configuration,
                CommonFunctions.getEnvironment());
      } catch (Exception h) {
         h.printStackTrace();
      }

      // Create a Hibernate session factory.
      try {
         System.out.println("SB: pre-buildSessionFactory()");

         m_factory = m_configuration.buildSessionFactory();

         System.out.println("SB: post-buildSessionFactory()");
      } catch (Exception h) {
         h.printStackTrace();
      }
      // Keep track of the singelton instance
      m_instance = this;
   }


And still got the same lack-of-exception response (note the username being cfuadm-no, which doesn't exist):


Code:
Checking catabase connectivity...
BS: OracleDAOFactory().getInstance()
BS: configureDatabaseForEnvironment()
BS: cfuadm-no/xxxxxxxx@jdbc:oracle:oci8:@db
SB: pre-buildSessionFactory()
SB: post-buildSessionFactory()
factory checked out
SUCCESS: Database connectivity checks out.

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 2:09 pm 
Beginner
Beginner

Joined: Fri Sep 08, 2006 7:29 am
Posts: 36
Try these......

1. Check the Application Server logs
2. Also check if the Application Server you are launching is in DEBUG mode..
3. Put Print statements in the catch block as well...

Shardul.

_________________
Shardul
Please Rate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 2:20 pm 
Newbie

Joined: Sun Sep 16, 2007 3:29 pm
Posts: 4
1. I'm not running in an app server.
2. Throwable.printStackTrace() should print just as well as System.out.println(), no?

Thanks, Brian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.