在hibernate中配置时,jdbc连接被拒绝

时间:2014-03-21 19:26:49

标签: java sql oracle hibernate jdbc

我使用oracle 12c和jar ojdbc7在hibernate中配置数据库。但是我得到了以下错误:

org.hibernate.exception.JDBCConnectionException:调用Driver#connect时出错     在org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator $ 1 $ 1.convert(BasicConnectionCreator.java:122)     at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140)     在org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58)     在org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75)     at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)     at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)     在org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)     at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)     在org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)     在org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)     at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)     在org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)     at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)     在org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)     在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)     在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)     在com.vikas.hibernate.HibernateTest.main(HibernateTest.java:21) 引起:java.sql.SQLException:Listener拒绝连接时出现以下错误: ORA-12505,TNS:监听器当前不知道连接描述符

中给出的SID
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:715)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55)
... 14 more

引起:oracle.net.ns.NetException:监听器拒绝连接时出现以下错误: ORA-12505,TNS:监听器当前不知道连接描述符

中给出的SID
at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:272)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:263)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
... 19 more

我的hibernate.cfg.xml如下:         oracle.jdbc.driver.OracleDriver         JDBC:预言:瘦:本地主机:1522 / DevDb         系统         oracle123

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.OracleDialect</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">create</property>

有人可以帮我解决这个问题。


它说

ORA-12505,TNS:监听器当前不知道连接描述符中给出的SID

我给出的SID是正确的。

2 个答案:

答案 0 :(得分:0)

你的jdbc连接字符串几乎是正确的

oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:localhost:1522/DevDb 

这是正确的

oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@//localhost:1522/DevDb

此外,在尝试ORM方式之前,请务必尝试使用sqlplus登录。

答案 1 :(得分:0)

您的设置是正确的,与persistence.xml中的设置无关 - &gt;较旧(hibernate.cfg.xml)

我在半夜的应用程序中看到了很短的时间,虽然这在服务器logg中有例外但在app-logg中没有。我分析了这个并且我的逻辑处理正确,这意味着这是一个oracleXE错误或app-server错误或ORM-Provider错误(hibernate)!这是肯定的,该应用程序自几个月以来一直在运行,但这个例子从未发生过,直到知道并且重点是nobdy调用了一个客户端调用!我重新启动服务器,每件事似乎都是正确的。

如果网络连接短时间停机并且因此无法访问服务器和数据库之间的数据对象的序列化,可能会发生这种情况,我不知道,它可能会发生,因为示例JBoss正在缓存数据!