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 is below:

<hibernate-configuration>

<session-factory>

    <!-- Database Connection Properties -->
    <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="hibernate.connection.pool_size">10</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>

</hibernate-configuration>

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?


Full stack trace is here: http://pastebin.com/KmWeVdqG

JUnit test is here: http://pastebin.com/HZbFdPPX

And just in case...Person Pojo class: http://pastebin.com/nuHEX0rr

What JDBC driver version? Are you able to the database using a database explorer software like SQLDeveloper? Also, instead of the connection URL you are using, can you try using the one mentioned in this article?

What JDBC driver version? Are you able to the database using a database explorer software like SQLDeveloper? Also, instead of the connection URL you are using, can you try using the one mentioned in this article?

This URL:? jdbc:oracle:thin:@host:1521:databaseName jdbc:oracle:thin:@127.0.0.1:8080:databaseName I tried it and it didn't work.

I can use Oracle SQL Developer to query the database. I tried using ojdbc5.jar and now using ojdbc6.jar. Not sure if those are the correct jars or not

You should be using the first connection string as 1521 is port on which Oracle database let you communicate by default. Port 8080 is HTTP alternate commonly used by Tomcat or other Java containers(servers).
Secondly you are trying to setup Java database connection so use JDBC driver

You can get the latest drivers for your specific database version from this page.

I'm a bit confused; in your original post you used the port 8080 whereas in the previous post you have 1521. What port is your database actually running on? Have you changed the port number or is it a default installation? What actually is "slyvronline" ? Your database name? SID? Service name? When connecting to your database using SQLDeveloper, which text field do you put "slyvronline" in?

Also, can you try to connect to your database from a standalone JDBC code which doesn't use Hibernate.

Oracle SQL Developer has this as the connection properties for my database:
connection name: 127.0.0.1:8080
username: system
password: *********
--Oracle tab
hostname:localhost
port:1521
sid: xe

I'm doing all this inside the web server i'm building 'slyvronline'. I'm a bit confused about which properties are actually supposed to be the url...hostname or connection name?

I'm not sure which version of oracle it is either...I thought it was 11g, but it might actually be (from getting started page on 127.0.0.1:8080--
Oracle® Database Express Edition Getting Started Guide
10g Release 2 (10.2)
B25610-01

Edit: I got it...I think. Needed ojdbc14.jar for 10g release 10.2 and changed the URL to be jdbc:oracle:thin:@127.0.0.1:1521:xe Getting this error now= HibernateException: Missing sequence or table: hibernate_sequence

Edit2: Solved! Added hibernate_sequence to my database and it seems to be hql'ing correctly. Thanks for you help

My Hibernate is rusty but after a bit of searching, it seems that you have an incorrect value for the "hibernate.hbm2ddl.auto" property in your configuration XML file. Just remove it or change it to 'create-drop' from 'validate' so that your existing table will be dropped and created new everytime. Also, read this for more details.

My Hibernate is rusty but after a bit of searching, it seems that you have an incorrect value for the "hibernate.hbm2ddl.auto" property in your configuration XML file. Just remove it or change it to 'create-drop' from 'validate' so that your existing table will be dropped and created new everytime. Also, read this for more details.

I don't want to drop my tables everytime I run a hibernate query. I did that while learning this at my internship and ended up dropping a bunch of tables (that shouldn't have been dropped). Validate lets you use hql without doing anything to your table structure

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.