Hello,
I am new to Hibernate, and I am receiving an odd error in my sample application for saving a session. Specifically, here is the error: "Hibernate Exception: Cannot Open Connection".
I find this error very odd because I am able to establish a connection and successfully drop my db schema using the hbm2ddl utility tool. So, I have been able to successfully establish a connection (when exporting my database schema).
Plus, I am fairly positive my hibernate.properties file is fine; I do not have a hibernate.cfg.xml file. Furthermore, the mapping files, properties file are all included in the classpath. I've included below the the code portion, properties file, and the stack trace.
I appreciate any feedback or help; I have been stuck for hours. Thanks in advance for taking the time to helping me out..!
Here is the code:
Code:
Configuration cfg = null;
SessionFactory sf = null;
Session session = null;
Properties props = new Properties();
try{
cfg = new Configuration()
.addClass(myDAO1.class)
.addClass(myDAO2.class)
.addClass(myDAO3.class);
sf = cfg.buildSessionFactory();
session = sf.openSession();
myDAO1 partner = new myDAO1();
myDAO1.setName("Joe");
session.save(partner);
session.flush();
session.connection().commit();
catch( MappingException me ){... }
}catch( HibernateException he ){ ...}
}catch( SQLException se ){...}
catch(HibernateException he1 ){...}catch( Exception e ){...}finally{
try{
if( session != null){
session.close();
}
}catch( HibernateException he ){
System.out.println( "HibernateException " + he.getMessage() );
}
}
Here is my Properties File
Code:
hibernate.dialect net.sf.hibernate.dialect.Oracle9Dialect
hibernate.dialect net.sf.hibernate.dialect.OracleDialect
hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
hibernate.connection.username user
hibernate.connection.password pwd
hibernate.connection.url jdbc:oracle:thin:@dev.aa.bb.cc.com:1234:sharedb
hibernate.show_sql=true
Here is the stack trace:
Code:
[java] WARNING: Could not obtain connection metadata
[java] java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
[java] at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
[java] at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
[java] at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
.......
[java] WARNING: SQL Error: 17002, SQLState: null
[java] Jan 11, 2005 4:51:04 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
[java] SEVERE: Io exception: The Network Adapter could not establish the connection
[java] Hibernate Exception: Cannot open connection
[java] Jan 11, 2005 4:51:25 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
[java] WARNING: SQL Error: 17002, SQLState: null
[java] Jan 11, 2005 4:51:25 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
[java] SEVERE: Io exception: The Network Adapter could not establish the connection
[java] Hibernate Exception: Cannot open connection