Results 1 to 7 of 7

Thread: Problem configuring Oracle and Hibernate

  1. #1
    Join Date
    Aug 2004
    Posts
    13

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    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.
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  3. #3
    Join Date
    Aug 2004
    Posts
    13

    Default

    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;;

  4. #4
    Join Date
    Aug 2004
    Posts
    203

    Default

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

    regards

  5. #5
    Join Date
    Aug 2004
    Posts
    13

    Default

    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.

  6. #6
    Join Date
    Aug 2004
    Posts
    13

    Default

    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.

  7. #7
    Join Date
    Sep 2008
    Posts
    1

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

Similar Threads

  1. Replies: 4
    Last Post: Nov 27th, 2009, 02:51 AM
  2. Replies: 5
    Last Post: Aug 25th, 2005, 04:16 PM
  3. Problem with hibernate 3 jar
    By berksgr in forum Data
    Replies: 4
    Last Post: Aug 1st, 2005, 09:30 AM
  4. Oracle Jdbc invalid url problem
    By jfuchs in forum Data
    Replies: 5
    Last Post: Nov 1st, 2004, 11:33 AM
  5. Replies: 2
    Last Post: Oct 12th, 2004, 07:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •