Creating Entity Classes from Database Schema Using Eclipse: In this tutorial will see how to generate entity classes from DB schema.
below are the required software’s to be installed in your local machine.
- JDK (1.6 or above)
- eclipse
- Jboss hibernate tools hibernate tools(check for your eclipse version to download required version)
- respective database drivers jars.
Steps to download and install Hibernate Tools
After installation of hibernate tools follow below steps for creating an entity class
Go to perspective and select database development as below screenshot
- Click on the new profile
- Selecting the database type from Popup
- Next, select the drivers in
- The eclipse will show predefined drivers version If your MySQL drivers in the list then select the respective driver’s configuration and upload the respective driver’s jar from the JAR List tab as below. if your MySQL version is not in the list then upload downloaded drivers jar from JAR List tab.
- Click in Add Jars/ZIP button to browse the driver’s jar file
- After uploading the driver’s jar you can see as the above screenshot
- Next, add the DB configuration Setting in Properties Tab
- In my case, localhost is my database IP address
- test is my database name
- root is the user name
- For drivers class click browse button as shown below
- Click blue dots button to add drivers class file
- Select drivers class as com.mysql.jdbc.Driver, click on ok button
- you will see the final configuration overview to finish setup as below
- Provide the password and confirm the database and user name and click on test connection you should see below alert
- Click on the Ok button on popup and click on Finish button
- you will see the connection details and database schema in left side Data Source Explorer
Now Step 2 Creating JPA project
- Change Perspective to JPA
- Create a new JPA Project as below steps
- Select JPA Project under JPA folder
- Use settings as the above screenshot
- Select the hibernate (JPA 2.1)
- Select the connection which we have created in step 1
- Click on Finish button you will see the project name in left side Project Explorer
- Next creating Entities using jpa project
- Right-click on JPA project to see below options
- Click on generate entities from tables
- enter the package name to where classes need to create and click on finish
- Respective Entity classes created with respective the tables in the database test
- copy paste the entity classes into your project folder
Happy programming
Creating Entity Classes from Database Schema Using Eclipse