Skip to main content

Hibernate Reverse Engineering Tutorial For Eclipse To Generate Java Classes From Oracle db

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.


Best Book To Learn Hibernate ( from what I've read so far)

Other Popular Hibernate Books




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

Popular posts from this blog

Building Autonomous Drone with Raspberry Pi and APM 2.8

I am a total newbie to hardware and was pushing my limits to see how far I can reach on with hardware projects (which sparked my interest lately). I have set out on a very ambitions mission  to control a drone from raspberry pi .I began the research for this around 2 months ago and had brought a raspberry pi, drone body kit and apm flight controller. The key difference of this project from common drone projects is that I'm trying to avoid the use of and RC and instead use the raspberry pi to control it.  Hardware Ins tallation Setup: I am using APM 2.8 and Mission Planner. I am using RPi 3 to control the APM 2.8 via Telem port of APM I am planning to power the apm via the battery to ESC (Electronic Speed Controllers) Now, documenting my steps below: Day 1 Watch Tutorial To get started with APM flight controller, I watched this video tutorial [1] which gives a gentle introduction about APM board.  Setup APM board and Calibrate Sensors I downloade...

Adafruit GFX - How to change line spacing in text?

  You may want to update the line spacing to be a little lower than default due to small screen size on IoT devices. I faced this challenge while working on a Watchy hobby project. You may have used a font generator or just using the default fonts and got a *.h file that has the details of the font. In that case just change the last integer value in the PROGMEM variable.

Data Mining & Analytics with R : Running R Scripts and Data Mining Techniques - Day 2

Warning: These are my messy study notes, much better legible notes can be found here  http://onepager.togaware.com 1. A Tour Thru Rattle Transform Tab ( by no means near to the full power of underlying R) Data Mining Tabs - Cluster, Associate Model Log Tab  - Capture the corresponding R command Working from Left to Right on Tabs  Remember to Click Execute Button 'Save' -> Projects save the current state, all models etc. 'Open' Projects can be restored at a later time You can even load it back to R  2. First R Program Load rattle and ggplot2 library(rattle)  # Provides the weather dataset  library(rattle)  # Provides the ggplot() function ggplot -> Grammar of Graphics : Just like english grammar or grammar of a computer language. A result of Hadley's Phd . Look him up to learn more details. Then produce a plot using ggplot() # handsondatascience.com - tips on elegantly writing repeated code ds ...