This tutorial will lays the ground work and help you learn how to generate your corresponding java entity classes from the database tables alone. Generating the java classes form the db schema via hibernate reverse engineering tools could save you tons of time if you're setting up a new project. I haven't rewritten the steps that's already published by someone, but I've organized them in a way that will be 'practically' helpful for any newbie who cannot get it right directly from the tutorials I've mentioned here. This is more of a kind a log of things I actually did while I referred these tutorials.
1. Download hibernate tools, only tools. From this tutorial in mkyong.com to install hibernate tools.
2. Create a java project 'HibernateExample'.
4. Select the jar file (ojdbc.jar) from lib folder of apache tomcat if required.
5. Click on 'Test Connection' and confirm that you've configured it properly.
6. Create the hibernate.cfg.xml. Enter the fields you know and leave the others blank.
7. Click Apply and then click 'OK' to close the dialog box.
8. Now in the hibernate perspective you can list out you database.
9.Choose "Hibernate Code Generation Configuration" from the tool bar. This is the phase where you generate the hibernate.reveng.xml file. Set-up a new hibernate.reveng.xml file. If you are new you could use the UI for specifying, otherwise you could write your own.
mine looks like
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<table-filter match-schema="<DB-NAME>" match-name="<TABLE1>"/>
<table-filter match-schema="<DB-NAME>" match-name="<TABLE2>"/>
</hibernate-reverse-engineering>
10. In the Exporters tab specify the things (DAO, ENTITY etc) that you want to generate.
11. Click on the 'Run' button and you are done.
Things to Check When Changing DB
Make sure that u right click this file > 'Edit Configuration' and give the new db configuration in the appearing window.
Each post takes two days or more of research and three hours of typing to bring out the high quality you see here. If you admire my effort, consider giving +1 to this post and Subscribe me in Facebook. You can also Follow Me on Twitter
Things to Check When Changing DB
Make sure that u right click this file > 'Edit Configuration' and give the new db configuration in the appearing window.
Best Book To Learn Hibernate ( from what I've read so far)
Other Popular Hibernate Books
- Hibernate Made Easy: Simplified Data Persistence with Hibernate and JPA (Java Persistence API) Annotations
- Beginning Hibernate (Expert's Voice in Java Technology)
Each post takes two days or more of research and three hours of typing to bring out the high quality you see here. If you admire my effort, consider giving +1 to this post and Subscribe me in Facebook. You can also Follow Me on Twitter
Comments
Post a Comment