• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Starting Hibernate (My First Hibernate program)

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I am starting Hibernate , i am getting the exception as

INFO: Configuration resource: /hibernate.cfg.xml
Error in initialiazation
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.enterprise.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
at com.enterprise.startup.CourseMain.saveCourse(CourseMain.java:19)
at com.enterprise.startup.CourseMain.main(CourseMain.java:12)
Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at com.enterprise.util.HibernateUtil.<clinit>(HibernateUtil.java:9)
... 2 more
Caused by: org.dom4j.DocumentException: http://www.jboss.org/dtd/hibernate/%20hibernate-configuration-3.0.dtd Nested exception: http://www.jboss.org/dtd/hibernate/%20hibernate-configuration-3.0.dtd
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
... 5 more


My Hibernate.cfg.xml file is as follows

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/ hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url"> jdbcracle:thin:@localhost:port/DB</property>
<property name="hibernate.connection.username">system</property>
<property name="connection.password">password</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect"> org.hibernate.dialect.Oracle10gDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="com/enterprise/config/tutorial.hbm.xml"/>
</session-factory>
</hibernate-configuration>

my classpath from eclipse is

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/transactions-jta.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/antlr-2.7.6.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/asm.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/atomikos-util.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/cglib-2.1.3.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/commons-collections-2.1.1.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/commons-logging-1.0.4.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/derby-10.2.2.0.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/derbytools-10.2.2.0.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/dom4j-1.6.1.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/hibernate3.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/jta.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/naming-factory.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/naming-resources.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/transactions.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/transactions-api.jar"/>
<classpathentry kind="lib" path="D:/Java Material/HibernateLib/hibernate3.1/lib/transactions-hibernate3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

The directory structure is attached

Please help me where i commited mistake.
HibernateDirectoryStructure.jpg
[Thumbnail for HibernateDirectoryStructure.jpg]
 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Replace your hibernate.cfg.xml with the following code


There are some subtle difference at the beginning of the file. Those might be causing the error for you. Let me know if replacing the code works for you
 
joseph prabhu
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks !

Now the previous error message vanished .

But now i got the error message as


SEVERE: JDBC Driver class not found: oracle.jdbc.driver.OracleDriver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

What jar File i have to give for this. Or Did i had duplicate version of Jar. Please look over my class path settings given in my first post.


 
joseph prabhu
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now i added the OJDBC14.jar , so erro "No class found error " went out.

NOw i got the exception as



java.sql.SQLException: No suitable driver
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.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
Please help me. My hands are near to Flower to pluck!
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can't find the jdbc driver. Make sure it's in your classpath.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
click the project menu-->properties-->java build files--libraries-->add external jar files-->select the ojdbc14.jar file from the location you stored it in. -->ok --> ok

and the url of the database should be "jdbc: oracle:thin:@localhost:1521:dbname"
dbname -put your oracle SID
1521 -put the port number configured for oracle on your machine default it is 1521

get these changes done and your program should run.

if it does not then show me your client program.
reply
    Bookmark Topic Watch Topic
  • New Topic