Wednesday, July 11, 2012

How to generate hbm POJO and DAO files from table using Eclipse

How to generate hbm POJO and DAO files from table using Eclipse

First we need to install "Hibernate prespectives" if you don't have already

1. go to 'help'  in eclipse
2. install new software and click on add button
3. provide this site in pop-up
for Galileo 3.5 :http://download.jboss.org/jbosstools/updates/JBossTools-3.1.1.GA

for Ganymede 3.4: http://download.jboss.org/jbosstools/updates/JBossTools-3.0.3.GA

for indigo: http://download.jboss.org/jbosstools/updates/stable/indigo/

4. install all software starting with 'Hibernate' name.

5. after installation you should be able to see Hibernate prespectives.


Then create new java project. file --> New --> java project
1. Right on project select New --> others --> Hibernate Configuration file --> next -->
2. Provide all required URL, driver class, uname and password etc..after these steps you should be able to see hibernate.cfg.xml file in your project
3.   a. Then right click on project New --> other --> select "Hibernate Reverse Engineering" then click on "NEXT" --> "NEXT" .

     b. Then right click on project New --> other --> select "Hibernate Console configuration" then click on "NEXT" --> "Finish" 

4. select "console configuration" and click on "Refresh" button it will take some time to your data scheme.
5. Once the schema available then include required tables to  generate hbm, POJO, DAO etc..
6. click on "finish" button
7. got to "Run" and select "Hibernate Code Generation"  then select "Hibernate Code Generation configuration"
8. Right click on "Hibernate Code Generation" and  "new" then fill required info(out put dir) in "Main" and "Exporter" tab
9. Then Click on "apply" and "Run" buttons

You should be able to see .hbm.xml, Pojo, Dao etc.. in out put directory.



You can find related info in below link
http://download.jboss.org/jbosstools/updates/











Cheers,
Shekhar reddy



1 comment:

mouli said...

you have to launch HibernateCodeGenerationconfigurations for generating the pojo , dao, config files.