• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem connecting to Oracle with Hibernate

 
Prashanth Chandra
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have been trying to configure Hibernate with Oracle but it is giving me an error saying not able to "Cannot open connection".

Below is the error :
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:384)
at org.hibernate.jdbc.JDBCContext.connect(JDBCContext.java:141)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:88)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:73)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:66)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:130)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1809)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2171)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:39)
Caused by: java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:381)
... 15 more


Please find my configuration file below :

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc racle:thin:@localhost:1521:test</property>
<property name="connection.username">wks_test</property>
<property name="connection.password">wks_test</property>
<property name="connection.pool_size">2</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="contact.hbm.xml" />
</session-factory>
</hibernate-configuration>


regards
Prashanth
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oracle's driver is usually

oracle.jdbc.driver.OracleDriver

you have

oracle.jdbc.OracleDriver

I'd also check the URL is correct, can you get into your database with SQLPlus?

Mark
 
Prashanth Chandra
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have changed the driver name to oracle.jdbc.driver.OracleDriver. But still facing the same issue.

Below is my XML file :

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc racle:thin:@localhost:1521:test</property>
<property name="connection.username">wks_test</property>
<property name="connection.password">wks_test</property>
<property name="connection.pool_size">2</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="contact.hbm.xml" />
</session-factory>
</hibernate-configuration>

regards
Prashanth
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prashanth,

Originally posted by Mark Spritzler:
Oracle's driver is usually
I'd also check the URL is correct, can you get into your database with SQLPlus?


You did not answer above question? Did you try?

Make sure that test is really your Oracle SID. Another thing is your user wks_test. What is the schema you try to access? Is it wks_test? If not, try the name of that schema as your user and not wks_test.

Once you have created a new schema with Oracle's Enterprise Manager Console application and set a password for it use these settings (schema name and password) for your connection file properties connection.username and connection.password.

Regards,
Darya
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And it looks like you are running Oracle on your local machine, are you sure the TNSListener and Oracle is up and running?

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic