In this article, we show you how to use Hibernate / JBoss Tools to generate Hibernate mapping files (hbm) and annotation code from database automatically.
Note: As i have used Maven to build project structure, so Maven already created 3 package for me:
2. New Hibernate Configuration
Select your project. Click on new for creating database connection, You need mysql-coonector-java-5.1.30.jar for this, so download it from mysql website.
Test Connection.. and click finish.
Now creating configurtion file, click on setup
Click on Apply and OK..
3. Hibernate Code Generation
Now, you are ready to generate the Hibernate mapping files and annotation codes.
- In “Hibernate Perspective”, click "Run As.." - > “Hibernate code generation” icon (see below figure) and select “Hibernate Code Generation Configuration”.

- Create a new configuration, select your “console configuration” (configured in step 2), puts your “Output directory” and checked option “Reverse engineer from JDBC Connection“.
- In “Exporter” tab, select what you want to generate, Model , mapping file (hbm) , DAO, annotation code and etc.
In my database 3 tables were present, here 3 hibernate mapping have been created. So finally we have created Hibernate Mapping files by using Eclipse reverse engineering.
Please post comments !
Tools required:
Eclipse v3.6 (Helios)
JBoss / Hibernate Tools v3.2
Oracle 11g
JDK 1.6
1. Open Hibernate Perspective
Open your “Hibernate Perspective“. In Eclipse IDE, select “Windows” >> “Open Perspective” >> “Others…” , choose “Hibernate“.
Note: As i have used Maven to build project structure, so Maven already created 3 package for me:
src/test/java
src/main/java
src/main/resources
If you haven't used Maven, then you can create these folders manually.
"src/main/resources" folder is required mostly for keeping hibernate file or other files which help in project configuration.
2. New Hibernate Configuration
In Hibernate Perspective, right click and select “Add Configuration”
In “Edit Configuration” dialog box,
In “Project” box, click on the “Browse..” button to select your project.
In “Database Connection” box, click “New..” button to create your database settings.
In “Configuration File” box, click “Setup” button to create a new or use existing “Hibernate configuration file”, hibernate.cfg.xml.
Select your project. Click on new for creating database connection, You need mysql-coonector-java-5.1.30.jar for this, so download it from mysql website.
Test Connection.. and click finish.
Now creating configurtion file, click on setup
Click on Apply and OK..
3. Hibernate Code Generation
Now, you are ready to generate the Hibernate mapping files and annotation codes.
- In “Hibernate Perspective”, click "Run As.." - > “Hibernate code generation” icon (see below figure) and select “Hibernate Code Generation Configuration”.

- Create a new configuration, select your “console configuration” (configured in step 2), puts your “Output directory” and checked option “Reverse engineer from JDBC Connection“.
- In “Exporter” tab, select what you want to generate, Model , mapping file (hbm) , DAO, annotation code and etc.
In my database 3 tables were present, here 3 hibernate mapping have been created. So finally we have created Hibernate Mapping files by using Eclipse reverse engineering.
Please post comments !
No comments:
Post a Comment