This tutorial is helpful to understand how hibernate work in MyEclipse.
MyEclipse Hibernate Introduction:
MyEclipse is an open-standard technology to provide a development environment
for different sources as java ,J2EE,web,UML,XML and databases.
It also include open source Eclipse platform. Hibernate is ORM based persistence
technologies of java, having exciting features to work in place of JDBC.
Now we are going to explain step by step how hibernate run in MyEclipse-
1.Creating a connection to our database :First step is to
connect database with which we want to build our application. For example, take
First open the database Explorer prospective and select MyEclipse
Database explorer. It will appear on left side of your window.
Click on create new connection and configure MYSQL Driver to connect to
the database. Click on Configure database link. By default there is only one
JDK driver, now add new by clicking on new button. Select the MYSQL
connector/J template from driver template.
Template will fill most of field with default values. Now add JARs that
provide jdbc Driver. By following the instruction we will see our new MYSQL
Driver that we configured.
MyEclipse automatically select the new driver for connection. Give the
name to the new connection as MYSQL Connection.
fill the real connection string by writing in URL
-jdbc:mysql://localhost/test. Next to fill user name and password as root.
Now we are ready to click on finish button to create new connection. On
DB Browser new MYSQL Connection is ready for use.
2.Creating a Hibernate-enabled Project: Now we have database
connection so the second thing to create Hibernate enabled project.
For creating hibernate project, we need to create any supportive type base
projects, like a java or web project.
and then you can add hibernate capabilities.
Create new java project named according to your choice. lets take name
Now set Hibernate capabilities. Select MyEclipse from menu bar and click on Add
Default setting is ok so leave all as it is and click on next button.
MyEclipse will create a new hibernet.cfg.xml.Click on Next button.
Now select the DB Connection profile which we created that is MySQL
Connection and click on Next button.
create Hibernate SessionFactory for MyEclipse popup window will display.
Now click on New button of Java package for creating New Package, suppose
Click on finished button now your project having all Hibernate and JDBC
libraries and is ready to work.
3. Reverse-engineering employee table into Hibernate (Java) objects :Now
we did database connection and properly configured a project so the next is
to tell MyEclipse to reverse-engineer our database table into Hibernate object.
Switch your perspective to the Database Explorer.
Now select the DB connection which we setup before. Open the it and see
your table existing in mysql DB.
You can see all fields of your table. When MyEclipse reverse-engineers
the table, a POJO is created having all properties same as fields.
For reverse-engineer the table just right click on the table and select
Hibernate Reverse Engineering. Now setup where the generated files go in
Java src folder..
Check on Hibernate mapping file to create hbm.xml.
Check on Java Data Object to create POJOs to map the table.
You can select Dao type on checking in DAO type.
Click on finish no we are in Hibernate perspective.