title: Hibernate can't open a connection with oracle 10g using jndi in JBoss
body: <p>I've got an application that runs on JBoss 4.2.3 and connects to an Oracle 10g DB.  We refactored the application to use spring roo.  Prior to trying to configure for jndi, we were using regular db connection strings and it was fine.  But now we're trying to use jndi and while JBoss registers the jndi and creates the data source bean, when hibernate actually has to open a connection, it fails to open.</p>
  
  <p>This is the configuration for persistence unit</p>
  
  <pre><code>&lt;persistence-unit name="persistenceUnitDev" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/&gt;
          &lt;!-- value="create" to build a new database on each run; value="update" to modify an existing database; value="create-drop" means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database --&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
          &lt;property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/&gt;
          &lt;property name="hibernate.connection.charSet" value="UTF-8"/&gt;
          &lt;property name="hibernate.show_sql" value="true"/&gt;
          &lt;property name="hibernate.connection.datasource" value="java:jdbc.DataSourceDev"/&gt;
          &lt;property name="hibernate.validator.apply_to_ddl" value="false" /&gt;
          &lt;property name="hibernate.validator.autoregister_listeners" value="false" /&gt;
          &lt;property name="jboss.entity.manager.jndi.name" value="java:jdbc.DataSourceDev"/&gt;
          &lt;property name="jboss.entity.manager.factory.jndi.name" value="java:/Manager1Factory"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>hibernate.cfg.xml</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
  &lt;session-factory&gt;
      &lt;property name="connection.datasource"&gt;java:jdbc.DataSourceDev&lt;/property&gt;
      &lt;property name="connection.autocommit"&gt;true&lt;/property&gt;
      &lt;property name="connection.release_mode"&gt;after_transaction&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
      &lt;property name="format_sql"&gt;true&lt;/property&gt;
      &lt;property name="use_sql_comments"&gt;true&lt;/property&gt;
      &lt;!--DB schema will be updated if needed --&gt;
      &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>application context defines the db beans:</p>
  
  <pre><code>&lt;jee:jndi-lookup id="jndiDataSource2" jndi-name="${database.jndiName}"/&gt;
  
  
  &lt;bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"&gt;
      &lt;property name="persistenceUnitName" value="${hibernate.persistenceunit}"/&gt;
      &lt;property name="dataSource" ref="jndiDataSource2"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>I'm at a loss as to why hibernate seems unable to open a connection.</p>
  
  <p>Edit: this is the log:</p>
  
  <p>2011-12-05 12:34:51,577 WARN  [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
  org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: Io exception: The Network Adapter could not establish the connection)
      at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:190)
      at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:619)
      at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:264)
      at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:575)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:347)
      at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:330)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:402)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:849)</p>
  
  <p>&lt;-- cut --></p>
  
  <p>Caused by: java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
      at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:441)
      at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)
      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
      at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:172)</p>