title: Listener refused the connection with the following error: ORA-12505
body: <p>I am having a problem while configuring a hibernate application. Please could you help me with this. I searched a whole lot of forums but could not find the solution. I know this question has been asked in previously, but the solution didn't work for me.</p>
  
  <p>Here is my hibernate.config file</p>
  
  <pre><code>&lt;!--
    ~ Hibernate, Relational Persistence for Idiomatic Java
    ~
    ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
    ~ See the lgpl.txt file in the root directory or &lt;http://www.gnu.org/licenses/lgpl-2.1.html&gt;.
    --&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/property&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;oracle.jdbc.driver.OracleDriver&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;manoj&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;manoj$123&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:oracle:thin:@localhost:1521/XE&lt;/property&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt;create&lt;/property&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;mapping class="com.manoj.java.hibernate.UserDetails"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>And here is my tnsnames.ora file</p>
  
  <pre><code>XE =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = XE)
      )
    )
  
  EXTPROC_CONNECTION_DATA =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      )
      (CONNECT_DATA =
        (SID = PLSExtProc)
        (PRESENTATION = RO)
      )
    )
  
  ORACLR_CONNECTION_DATA = 
    (DESCRIPTION = 
      (ADDRESS_LIST = 
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) 
      ) 
      (CONNECT_DATA = 
        (SID = CLRExtProc) 
        (PRESENTATION = RO) 
      ) 
    ) 
  </code></pre>
  
  <p>And here is my listener.ora file</p>
  
  <pre><code>SID_LIST_LISTENER =
    (SID_LIST =
      (SID_DESC =
        (SID_NAME = XE)
        (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
      )
      (SID_DESC =
        (SID_NAME = PLSExtProc)
        (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
        (PROGRAM = extproc)
      )
      (SID_DESC =
        (SID_NAME = CLRExtProc)
        (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
        (PROGRAM = extproc)
      )
    )
  
  LISTENER =
    (DESCRIPTION_LIST =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
        (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      )
    )
  
  DEFAULT_SERVICE_LISTENER = (XE)
  </code></pre>
  
  <p>I added the SID Desc of XE in listener.ora which if I remove, then also it was not working.</p>
  
  <p>and here is my exception log</p>
  
  <pre><code>Apr 22, 2017 11:40:01 AM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {5.2.9.Final}
  Apr 22, 2017 11:40:01 AM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  Apr 22, 2017 11:40:02 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
  Apr 22, 2017 11:40:02 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
  Apr 22, 2017 11:40:02 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
  INFO: HHH10001005: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:localhost:1521:orcl]
  Apr 22, 2017 11:40:02 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
  INFO: HHH10001001: Connection properties: {user=manoj, password=****}
  Apr 22, 2017 11:40:02 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
  INFO: HHH10001003: Autocommit mode: false
  Apr 22, 2017 11:40:02 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections &lt;init&gt;
  INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
  Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
      at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
      at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
      at com.manoj.java.session.HibernateSession.main(HibernateSession.java:15)
  Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
      at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:105)
      at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:123)
      at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41)
      at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
      at org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:123)
      at org.hibernate.engine.jdbc.connections.internal.PooledConnections.&lt;init&gt;(PooledConnections.java:42)
      at org.hibernate.engine.jdbc.connections.internal.PooledConnections.&lt;init&gt;(PooledConnections.java:20)
      at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:161)
      at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:109)
      at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:72)
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
      ... 14 more
  Caused by: java.sql.SQLException: Listener refused the connection with the following error:
  ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
  
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489)
      at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:553)
      at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:254)
      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
      at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
      ... 29 more
  Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
  ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
  
      at oracle.net.ns.NSProtocol.connect(NSProtocol.java:399)
      at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1140)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340)
      ... 34 more
  </code></pre>
  
  <p>Please if somebody could guide me, how can I get this thing right?</p>
  
  <p>This question was marked duplicate, but i am not finding the answer still, so I am reposting this question.</p>