Connect MySQL with Hibernate 4 in NetBeans,MyEclipse,RAD

Hibernate is a ORM (Object/Relational Mapping) framework.To connect MySQL with hibernate , It requires additional jar files. Hibernate is not an installable software .

Basic requirements to Connect MySQL with Hibernate :

connect MySQL with HibernateSoftwares :

…….Java  (Download Java)
…….MySQL (Download MySQL)

connect MySQL with HibernateJar files: (Download Hibernate 4 jars)


connect MySQL with HibernateFiles :


Directory Structure

MyEclipse :

connect MySQL with Hibernate

NetBeans :

connect MySQL with Hibernate



connect MySQL with Hibernate Create new java project .

 Add all the jar files to the libraries .

 Create Employee table in the database and insert few records.

 Copy the four (two java,two xml) files .

 Finally , run the  file .


Note : Here we created , and Employee.hbm.xml files in the <default package>.You can also create these files in a separate package (Ex : EmpApp) and do the following changes :

Connect oracle with hibernate Change 1 . In hibernate.cfg.xml : <mapping resource=”Employee.hbm.xml“/> to <mapping ….resource=”EmpApp/Employee.hbm.xml“/> .

Connect oracle with hibernate Change 2 . In Employee.hbm.xml : <class name=”EmpBean” table=”Employee”> to <class ….name=”EmpApp.EmpBean” table=”Employee”>

Connect oracle with hibernate Change 3 . Add the package name (package EmpApp; ) as a first line in the .java files.


Example code to  Connect MySQL with Hibernate : (main class): (Bean class ) :

hibernate.cfg.xml  (Hibernate configuration file) :

Employee.hbm.xml (Mapping file) :

Create Employee table in MySQL data base :



Output : Run the main class as a java application .

connect MySQL with Hibernate


Note : If you are running the above application , from command prompt , copy all 4 files in a folder and add the jar files to class path.

Related Posts :
Call database in Jsp (Access Oracle , MySQL , PostgerSQL ,Db2 from Jsp)
Hibernate error user_sequences doesn’t exist in mysql ( resolved )
Jsp , Servlet and JDBC login application example in NetBeans
Connect DB2 with Hibernate 4 in MyEclipse,NetBeans,RAD
Connect PostgreSQL with Hibernate 4 in Myeclipse,NetBeans,RAD
Connect oracle with hibernate in MyEclipse, NetBeans, RAD
Jdbc with Mysql in NetBeans and MyEclipse
Jdbc with PostgreSQL using MyEclipse and NetBeans
   [will not be published]

^ <