slyvr
slyvr

Reputation: 33

Hibernate fails to open Connection with Oracle 11g?

I made a basic JUnit test to set up this Oracle database on my computer with hibernate. The database works and everything, but trying to hook it up to Hibernate is proving to be a challenge. My config file can be here:

The JUnit test is fairly straight forward and I'm sure it should work, but I'm getting this JUnit failure:

org.hibernate.exception.JDBCConnectionException: Cannot open connection

Any ideas what's wrong with it?

Connection properties in Hibernate config file:

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

Upvotes: 3

Views: 28320

Answers (3)

Ram
Ram

Reputation: 1591

When you are connecting with oracle, no need to mention the schema name so the connection URL looks like as below

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

Upvotes: 1

Dave Newton
Dave Newton

Reputation: 160191

It's unlikely (but possible) your DB is listening on port 8080. Oracle defaults to port 1521. Start there.

(Since it's a connection issue, relevant portions of Hibernate config are useful; I've edited to reflect.)

Upvotes: 7

There are possible two issues in your connection string

first is the port that Dave Newton, second that after port you should add the sid after : not /.

So try this as a solution:

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

Upvotes: 3

Related Questions