Running First Hibernate 3.0 Example

Hibernate is free open source software it can be download from http://www.hibernate.org/6.html. Visit the site and download Hibernate 3.0.

Ads

Tutorials   
Hibernate 5 native query example Hibernate 5 query deprecated When should you use Hibernate? What's new in Hibernate 5? How much time it takes to learn Hibernate? Hibernate envers custom revinfo table Hibernate 5 Envers Hibernate Envers get all revisions Hibernate Examples Hibernate 5 build SessionFactory Example Hibernate 5 SessionFactory Example Hibernate 5 Annotation Example How to download Hibernate 5.x? Hibernate 5 Features Hibernate 5 Tutorials Learning Hibernate ORM - Free Training/Tutorial videos of Hibernate ORM with Java How to write hello world example program in Hibernate? How to create one to one relationship in Hibernate 4 with Annotation? How to calculate minimum in Hibernate using the min() Function Hibernate ORM 4.2.21.Final Released - Create CURD application in latest Hibernate Hibernate ORM 4.2.21 Tutorial - Learn Hibernate ORM Framework Hibernate Error: Failed to create sessionFactory object.java.lang.NoClassDefFoundError How to create Hibernate Project in Eclipse? Examples of Hibernate Criteria Query Hibernate ORM 4.3.6.Final released Hibernate ORM 4.2.14.Final released Hibernate 4.3.4 Released: Hibernate 4.3.4.Final Maven dependency Hibernate association and join example Learn Hibernate programming with Examples Introduction to Hibernate Framework Hibernate Tutorial: Learn Hibernate with examples Hibernate 4.3 Hello World: Example Hibernate ORM 4.3.1.Final released How to create SessionFactory in Hibernate 4.3.1? Hibernate 4 Hello World: Example of Hello World program Hibernate 4 create Session Factory: Example of creating Session Factory in Hibernate 4 Hibernate 4.3 and JPA 2.1 Example What is Hibernate in Java? Hibernate Overview and Architecture What is JPA 2.1?

Running First Hibernate 3.0 Example

     

Hibernate is free open source software it can be download from http://www.hibernate.org/6.html. Visit the site and download Hibernate 3.0.

This is very easy to follow tutorial and you can create your first project very easily. In this example we are connecting our program to MySQL database and then performing insert operation.

The Entity class in this application is Contact.java, which is mapped to the contact table of database.

After running the code example you may check your MySQL database to confirm the new record which is added into table.

Prerequisite:

Here are few prerequisite to run the application.

  • Java installed and configured on your computer
  • Eclipse IDE installed
  • MySQL Installed and running.
  • Creation of Database: Database hibernatetutorial must be created before running the example.

You can download the Hibernate and install it yourself. But I have provided very thing in one zip file. Download the example code and library from here and extract the content in your favorite directory say "C:\hibernateexample". Download file contains the Eclipse project. To run the example you should have the Eclipse IDE on your machine. Start the Eclipse project and select Java Project as shown below.

Click on "Next" button. In the new screen, enter "hibernateexample" as project name and browse the extracted directory "C:\hibernateexample". 

Click on "Next" button. In the next screen leave the output folder as default "hibernateexample/bin" .

Click on the "Finish" button.

Now Open the FirstExample.java in the editor as show below.

 

Copy  contact.hbm.xml, and hibernate.cfg.xml in the bin directory of the project using windows explorer. You may have to change the database username and password if credential is different in hibernate.cfg.xml file. To run the example select Run-> Run As -> Java Application from the menu bar as shown below.

This will run the Hibernate example program in Eclipse following output will displayed on the Eclipse Console.

In this section I showed you how to run the our first Hibernate 3.0 example.

Advertisements

Ads
Share on Google+Share on Google+

Running First Hibernate 3.0 Example

Posted on: January 8, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Running First Hibernate 3.0 Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:6
aabideen
May 29, 2011
Hibernate - not updated in table

I've executed "first hibernate" example. This program executed without any error. but values not inserted into table. --> please share your knowledge
Wouter Meijer
June 25, 2011
commit missing

Had to add autocommit property to get this code insert a row in the database. A commit is required. But thanks, I learned Hibernate can be used stand alone without an application server :-)
sridhar
December 27, 2011
first hibernate example

i have followed the steps and able to create tables in mysql and also the message is displayed in console that record is inserted. But, I am unable to see those record in the table in the database. Could you let me know where the mistake.
aun asghar
December 30, 2011
Given example not affecting database

FirstHibernateExample is succesfully running with no exceptions or errors but i dont see any impact on my db table. i have even set autocommit property as true.
abdou
December 9, 2012
thant's

thank you very much for this tutorial...
Wouter Meijer
June 25, 2011
Not updated in table

Had to add autocommit property to get this code insert a row in the database. A commit is required. But thanks, I learned Hibernate can be used stand alone without an application server :-)

Ads

 

Ads