• 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

Hibernate cfg xml and Eclipse problem

 
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have Eclipse Europa and am trying to do a hibernate example in it.
I am trying to simply add an entry to the database.

My hibernate.cfg.xml file is as follows:



Eclipse keeps showing errors for this xml.

An when I run the class with the hibernate code it shows/throws the following error.



My java classes are in the src folder, there is no package hierarchy. The hibernate.cfg.xml file is placed in the bin folder.
Is this an Eclipse issue is there an error in the way the xml is written.
How do I get this resolved.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




Use the correct DOCTYPE element for configuration file, you have used the one for the mapping file.
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Here is the hibernate.cfg.xml again:



The DOCTYPE element has been modified.

Still getting error:



 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be the changes are still not visible?
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The changes were in place when I restarted Eclipse.
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Priety Sharma wrote:The changes were in place when I restarted Eclipse.


You don't need to restart eclipse but the file should be copied to the classpath when you run it in order to read it.
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

A little confused here.
I have the hibernate.cfg.xml file in the bin folder of my project.
If I remove it from there it says hibernate.cfg.xml not found.
Which means that it is where it should be.

After putting it back there it still gives the same error.

 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Priety Sharma wrote:If I remove it from there it says hibernate.cfg.xml not found. Which means that it is where it should be.


Yes, that's what I mean, it should be found in the CLASSPATH. If you still get the parse exception all I can say is just check your xml against the reference of the Hibernate version you are using thoroughly.
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.


Now I have somehow managed to get rid of the xml error.

I am using hibernate3.3.0. Database is derby.


Getting a new error.
java.lang.NoClassDefFoundError

This piece of code is throwing an exception when the buildSessionFactory() method is called.


Even though its in the try block the control goes directly to the finally block and then the exception is printed.

Exception message:



My AddJob class:



Please help.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change the Name of all the files (xml & java)and try again.
What is your mapping file???
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Looks like I am almost there. Added commons-collections-3.2.1jar and got rid of an intermediate error.



Now I am getting a for:



This is the driver I am trying to use to connect to derby.


I put the import in my java file just to check if its available an the EmbeddedDrive class is there.

Still get the above mentioned error.
Which driver class should I use.

Derby version is 10.3.1

Stuck again.
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Looks like your JDBC driver is not in the classpath.
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It must be there.
Since in the same project I have a class called Derbyconnectiontest.java and it simply test connecting to derby.

It works.
In this class I have used


as the driver.

This is the same driver I have mentioned in my hibernate.cfg.xml file in the same eclipse project.

The configuration xml again:



Then why is it not working?
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vijitha,

Good news here.
I have finally been able to run the hibernate code and put records in the derby database.
After trying for almost the whole day things fell into place.

The driver error mentioned was due to the url property not being as expected:

The value which works is:


and not this:



Since my class to test the connection to the derby database was working properly and still the problem was present when connecting to derny through hibernate code I was confused.

I read a thread on another forum where someone had mentioned that it had to be a URL problem.
So finally got the URL right and code started working.



Thanks for all the replies and the help.

This is a relief.
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to hear that worked finally
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic