Announcement Announcement Module
Collapse
No announcement yet.
Problem configuring Oracle and Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem configuring Oracle and Hibernate

    On Spring startup, I'm getting the SQLException "Io exception: The Network Adapter could not establish the connection" thrown from the Oracle driver. I am running Oracle 9.2.0.5.

    I am able to establish a connection normally using plain JDBC and even Apache DBCP BasicDatasource. Using my colleague's PC, I can connect with Hibernate outside of Spring as well.

    Steps I have tried are to use spring's driver manager data source, apache dbcp's data source and even hibernate's own built-in data source, all resulting in the same error. What could be causing the error?

    Below is my applicationContext-hibernate.xml and the stack trace.


    applicationContext-hibernate.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    
    	<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
    		<property name="url"><value>jdbc&#58;oracle&#58;thin&#58;@l55.161.154.154&#58;1521&#58;tst</value></property>
    		<property name="username"><value>myuser</value></property>
    		<property name="password"><value>mypassword</value></property>
    	</bean>
        <bean id="mySessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
            <property name="mappingDirectoryLocations">
               <list>
                   <value>src/classes</value>
               </list>
           </property>
    
            <property name="hibernateProperties">
    		  <props>
    		    <prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
    		    <prop key="hibernate.query.substitutions">true=1 false=0</prop>
    		    <prop key="hibernate.show_sql">true</prop>
    		  </props>
    		</property>
            <property name="dataSource"><ref bean="myDataSource"/></property>
    	</bean>
         <bean id="transactionManager"
            class="org.springframework.orm.hibernate.HibernateTransactionManager">
            <property name="sessionFactory"><ref local="mySessionFactory"/></property>
         </bean>
         
    	<bean id="userDao" class="com.fedex.tmsc.dao.persistence.hibernate.UserDaoImpl">
            <property name="sessionFactory">
                <ref bean="mySessionFactory"/>
            </property>
    	</bean>
    </beans>

    Stack trace:

    Code:
    WARNING&#58; Error while getting database metadata
    org.springframework.jdbc.support.MetaDataAccessException&#58; Error while getting connection; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException&#58; Could not get JDBC connection; nested exception is java.sql.SQLException&#58; Io exception&#58; The Network Adapter could not establish the connection
    org.springframework.jdbc.CannotGetJdbcConnectionException&#58; Could not get JDBC connection; nested exception is java.sql.SQLException&#58; Io exception&#58; The Network Adapter could not establish the connection
    java.sql.SQLException&#58; Io exception&#58; The Network Adapter could not establish the connection
    	at oracle.jdbc.driver.DatabaseError.throwSqlException&#40;DatabaseError.java&#58;158&#41;
    	at oracle.jdbc.driver.DatabaseError.throwSqlException&#40;DatabaseError.java&#58;206&#41;
    	at oracle.jdbc.driver.DatabaseError.throwSqlException&#40;DatabaseError.java&#58;382&#41;
    	at oracle.jdbc.driver.T4CConnection.logon&#40;T4CConnection.java&#58;333&#41;
    	at oracle.jdbc.driver.PhysicalConnection.<init>&#40;PhysicalConnection.java&#58;371&#41;
    	at oracle.jdbc.driver.T4CConnection.<init>&#40;T4CConnection.java&#58;148&#41;
    	at oracle.jdbc.driver.T4CDriverExtension.getConnection&#40;T4CDriverExtension.java&#58;32&#41;
    	at oracle.jdbc.driver.OracleDriver.connect&#40;OracleDriver.java&#58;572&#41;
    	at java.sql.DriverManager.getConnection&#40;Unknown Source&#41;
    	at java.sql.DriverManager.getConnection&#40;Unknown Source&#41;
    	at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager&#40;DriverManagerDataSource.java&#58;156&#41;
    	at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager&#40;DriverManagerDataSource.java&#58;144&#41;
    	at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnection&#40;DriverManagerDataSource.java&#58;132&#41;
    	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection&#40;DataSourceUtils.java&#58;173&#41;
    	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection&#40;DataSourceUtils.java&#58;152&#41;
    	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection&#40;DataSourceUtils.java&#58;128&#41;
    	at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData&#40;JdbcUtils.java&#58;93&#41;

  • #2
    That error indicates a networking issue - I would double check the ip adress and make sure that you can ping that address from the machine where you are running your code on. I would also try to connect with plain JDBC using the exact same url. If you can connect from that machine usng plain JDBC then it should work using any other datasource with Spring and Hibernate.

    Comment


    • #3
      I have connected using plain JDBC, and it works perfectly on the machine I am running the code on. This is a reason I'm so puzzled.

      I'm running the latest Spring 1.1.1.

      Code:
          	
      String url = "jdbc&#58;oracle&#58;thin&#58;@155.161.154.154&#58;1521&#58;tst";
      Connection con = DriverManager.getConnection&#40;url, user, password&#41;;
      Statement stmt = con.createStatement&#40;&#41;;
      ResultSet rs = stmt.executeQuery&#40;"select 1 from dual"&#41;;
      rs.next&#40;&#41;;
      System.out.println&#40;rs.getString&#40;1&#41;&#41;;
      con.close&#40;&#41;;

      Comment


      • #4
        Hello,
        Spring grab another file config file , maybe.Your setting is fine

        regards

        Comment


        • #5
          Anyone else have any ideas? It seems to work perfectly outside of Spring.

          Code:
          ApplicationContext context = new FileSystemXmlApplicationContext&#40;"web/WEB-INF/applicationContext-hibernate.xml"&#41;;
          It also works with Spring on another PC. My suspicion is that it has something to do with my WinXP / network connection, but I can't figure out how come normal JDBC would work but Spring would fail on my PC.

          Comment


          • #6
            Apparently it is a problem with my database hostname and any connection pool, nothing to do with Spring. Thanks for the quick responses and verification of my files.

            A Google for my Oracle error returns
            http://www.websina.com/bugzero/kb/or...onnection.html

            I managed to solve it by implementing the long version of the JDBC thin url. Fyi for anyone who may encounter a similiar problem.

            Comment


            • #7
              proble in spring with No ManagedConnections available

              Hi,

              Following error simply says required database object are locked,we can see the same in DB administrator page.There is nothing to do with Spring or ds configuration file.

              2009-10-13 12:33:55,899 INFO [com.egatesolutions.eso.dao.serviceorder.hibernate. ServiceOrderDaoImpl] GenericService::Find Method
              2009-10-13 12:34:06,920 WARN [org.springframework.jdbc.support.SQLErrorCodesFact ory] Error while extracting database product name - falling back to empty error codes
              org.springframework.jdbc.support.MetaDataAccessExc eption: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not get JDBC Connection; nested exception is org.jboss.util.NestedSQLException: No ManagedConnections available within configured blocking timeout ( 30000 [ms] );

              Thanks,
              Praveen Kumar(Mlbs)

              Comment

              Working...
              X