【问题标题】:Hibernate fails to open Connection with Oracle 11g?Hibernate 无法打开与 Oracle 11g 的连接?
【发布时间】:2011-12-08 20:44:02
【问题描述】:

我做了一个基本的 JUnit 测试,以便在我的计算机上使用 hibernate 设置这个 Oracle 数据库。数据库工作正常,但尝试将其连接到 Hibernate 被证明是一个挑战。我的配置文件可以是here:

JUnit 测试相当简单,我确信它应该可以工作,但是我遇到了这个 JUnit 失败:

org.hibernate.exception.JDBCConnectionException: Cannot open connection

有什么想法吗?

Hibernate 配置文件中的连接属性:

<session-factory>
    <property name="hibernate.connection.driver_class">
        oracle.jdbc.OracleDriver</property>
    <property name="hibernate.connection.url">
        jdbc:Oracle:thin:@127.0.0.1:8080/slyvronline</property>
    <property name="hibernate.connection.username">
        YouNoGetMyLoginInfo</property>
    <property name="hibernate.connection.password">
        YouNoGetMyLoginInfo</property>
    <property name="dialect">
        org.hibernate.dialect.OracleDialect</property>
    <!-- Other -->
    <property name="show_sql">true</property>
    <property name="hibernate.hbm2ddl.auto">validate</property>

    <!-- Mapping files -->
    <mapping class="com.slyvr.pojo.Person"/>
</session-factory>

【问题讨论】:

    标签: java oracle hibernate oracle11g


    【解决方案1】:

    使用 oracle 连接时,无需提及架构名称,因此连接 URL 如下所示

        jdbc:oracle:thin:@<hostname>:<port>:<sid>
        ex:
        jdbc:oracle:thin:@localhost:1521:xe
    

    【讨论】:

      【解决方案2】:

      您的数据库不太可能(但可能)正在侦听端口 8080。Oracle 默认使用端口 1521。从那里开始。

      (由于是连接问题,Hibernate 配置的相关部分很有用;我已经编辑以反映。)

      【讨论】:

      • 啊,你是对的。该 URL 似乎正在使用:jdbc:oracle:thin:@localhost:1521:xe。除非我收到一条错误提示 Missing sequence or table: hibernate_sequence
      • @slyvr 这是一个映射问题;应该在一个新问题下。
      【解决方案3】:

      你的连接字符串可能有两个问题

      首先是 Dave Newton 的端口,其次是端口之后您应该在 : 之后添加 sid :而不是 /。

      所以试试这个作为解决方案:

      jdbc:Oracle:thin:@127.0.0.1:1521:slyvronline
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-10
        • 2015-02-15
        • 2011-03-13
        • 2014-07-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多