Wednesday, 15 May 2013

Reverse-engineer POJOs from a database

In this post, we will see how to create POJO from the existing database (reverse engineering). 

First let us setup the development environment. Download this document and follow the step by step instruction to install the necessary software’s.

We are going to create POJO from the existing database in mysql. So let us download driver for the same. You can download the driver here

Step 1:
In the Eclipse, Select File –> New –> Other->JPA Project

image

Click Next

image
Enter the Project Name and leave all the other options as default and click Next.
image
Click Next
image
For JPA Implementation Type , select Disable Library Configuration
Next click Add connection, Select mysql

image
Click Next
image
Select New Driver Information next drivers drop down.

image
Select MYSQL 5.1 and goto JAR List tab. Add the Connector zip file which we downloaded earlier.

image

Click ok and Test your mysql connection in the following screen.
image

After testing the connection, you can click finish and come back to starting screen

image

Now you can click finish button to create the project with the connection information.

image

Now click on the Project Name and Right Click, Select New –> JPA Entities from the Tables

image

It will show all the tables in the connected database. You can choose all the tables and Click Next

image

You can verify all the foreign key relationship. In this example, i do not have more than one table, so it is empty. Click Next

image

Here you can Key Generator as Identity and you can modify/leave to default for other properties.Click Next

image

Click Next and Click Finish
Now You can see all the POJO classes are created with the relationship.

No comments:

Post a Comment