You can view the tutorials best in Google Chrome, Mozilla Firefox, Opera, higher version of Internet Explorer

Hibernate Hello World Program in Eclipse

Hibernate » On Jun 9, 2011 By Sivateja

Mates, now am going to show like how to execute the previous hibernate program in Eclipse IDE to make our world little easy. You might be fresher or not aware of executing java programs in the eclipse what ever just follow these setps…..

1. Download Eclipse IDE for Java EE Developers
Unzip and open Eclipse
3. Now create a new java project like, File –> New –> Java Project

4. See now it will opens one window, there give the project details like project name and keep the other details as it is.. and press Finish

5. so you have been created one new java project and at the left side you must see like.. (Before this, make sure you have been selected navigator view in windows –> show view –> Navigator)

6. create the following files in the src folder..

  • In the src create sub folder with name  str(like package) , and create 2 xml files with names hibernate.cfg.xml and Product.hbm.xml
  • In the str folder create 2 more java files with names, and
  • so the final directory structure will be..

Actually our work is to do every thing in src folder and Eclipse will automatically create  and copies all the related .classes files, folders and .xmls in bin folder, what am saying is as a programmer we no need to touch bin folder, ours is src only :-)

7. Now copy and paste the code into the files in the eclipse..
8. Finally double click on so that file will be opens, then right click on the code and Run As –> Java Application

9. Now see the console.., it will be like

That’s it…, you are done..!!

And finally in the database

And mates, this is the same process for the hibernate applications, actually its little time taking for me to give all the examples in the Eclipse so from the next example am going to give related files only, you can carry on with Ecliplse  ;)


By ( Java/J2EE Developer & Web Designer )
Founder of You can contact me at sivateja [at]


21 Responses to “Hibernate Hello World Program in Eclipse”
  1. ramya says:

    this is very nice tutorials for beginners,….it helped me a lot….thanks

  2. Surendra Kumar says:

    When i run this code i got such type of error how can i resolve this error
    Configuration cannot be resolved to a type
    Configuration cannot be resolved to a type
    SessionFactory cannot be resolved to a type
    Session cannot be resolved to a type
    Transaction cannot be resolved to a type

  3. Java4s says:


    You welcome :-) glad to hear that its helped you.

  4. Java4s says:

    @Surendra Kumar

    Hi seems you are not added .jar files in your class path.

    Do one thing..

    Right click on your project –> Build Path –> Configure Build Path_

    Add your hibernate jar files there, hope you will be fine with this.

  5. Pavan says:

    Hi Sir,i am beginner in hibernate and great tutorials really love to study.Can u tell me sir before running the hibernate program do i need to create the table structure in the database or table creation is done by itself internally.

  6. Java4s says:


    Actually thing is, in hibernate.cfg.xml if we set property value to update, then hibernate will automatically update the table in the database, and creates the table if not exist in the database.

    You will see about this in future articles, for now just remember as you are fresher :-)

  7. sample java says:

    Hi sir,

    you are doing all coding in eclipse, I need to know how about netbeans


  8. Davis says:

    “The import org.hibernate cannot be resolved” this is what i see in file. what to do?

  9. Java4s says:


    Make sure you set Jar files in your class path, before you start.

  10. Jsam says:

    Thanks a lot. as i m a beginner it helps me a lot… it helped me to make a first step in hibernate… when i master the hibernate , that credit goes to you :-)


  11. saikiran says:

    instead of saying sub folder like package in src , say as source folder. thanks done with my first hibernate project..kudos for ur effort

  12. Srinivas N says:

    I tried to create a sample program using hibernate but getting below error.

    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread “main” org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(
    at org.hibernate.cfg.Configuration.configure(
    at com.srinivas.hibernate.StoreData.main(
    Caused by: org.dom4j.DocumentException: Error on line 1 of document : A pseudo attribute name is expected. Nested exception: A pseudo attribute name is expected.
    at org.hibernate.cfg.Configuration.doConfigure(
    … 2 more

    Please help me, and redirect your replies to my email TIA.

  13. Exception in thread “main” java.lang.NoClassDefFoundError: org/dom4j/DocumentException
    at str.ClientForSave.main(
    Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
    at Method)
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    … 1 more
    What’s the Cause of the error?

  14. Exception in thread “main” java.lang.Error: Unresolved compilation problems:
    Configuration cannot be resolved to a type
    Configuration cannot be resolved to a type
    SessionFactory cannot be resolved to a type
    Session cannot be resolved to a type
    Product cannot be resolved to a type
    Product cannot be resolved to a type
    The method commit() is undefined for the type Transaction

    at str.ClientForSave.main(

    How do i add the jar files please let me know the steps

  15. Vaishali says:

    best tutorial i have ever seen….

  16. suv says:

    I have put the components in the same folder. But I am getting the error Exception in thread “main” org.hibernate.MappingException: entity class not found: Employee. Please help

  17. P.Pradeep says:

    Excellent tutorial for all thank a lot to the creator of this site…

  18. TULASI says:

    Current Hibernat version is 4.5.1 ……But You are using 3.2.2
    Which version are most market using right now?Can you tell me?

  19. Sunny says:

    Im Still getting an error … This is what i get. Please help in solving this error.

    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread “main” org.hibernate.HibernateException: src/hibernate.cfg.xml not found
    at org.hibernate.util.ConfigHelper.getResourceAsStream(
    at org.hibernate.cfg.Configuration.getConfigurationInputStream(
    at org.hibernate.cfg.Configuration.configure(
    at str.StoreData.main(

  20. Kamal says:

    i am getting error given below: please help me…

    Exception in thread “main” java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/MetadataProvider
    at str.ClientForSave.main(
    Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.MetadataProvider
    at$ Source)
    at$ Source)
    at Method)
    at Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 1 more

  21. James says:

    Hi.thanks for the brilliant tutorial it helps many of us in many beginner to hibernate .I’m trying insert 2 records in table ,however when i set data in objectfor the first time and do an insert it hits the database and record is inserted ,however when i try to add the 2 nd record in the same session object ,the previous data is getting overridden .I’m confused.Please explain.How do i add more than one records in a table.



By posting your answer, you agree to our comments policy.
So, What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs

Most Recent Tutorials
Hibernate Recent Posts
Spring Recent Posts
Struts Recent Posts
Recomandded Links
Current & UpComing Tutorials
Sitemap :
spring Hibernate struts Json Ajax Log4j Log4j coreJava Servlets Web Services

  Web Services [ SOAP ], JSP
Facebook_Java4s  Twitter_Java4s  GooglePlus_Java4s  Youtube_Java4s 
© 2010 - 2014 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.