Sometime we need to generate entities from the database table or vice versa. Off course we can do it manually, but that is huge time consuming process.
In those situations, JPA Tools comes into action and plays a handy role creating the entities from already existing the database. How can we do that in our project.
- Convert the project into JPA Project. (Right click on project -> configurations -> convert to JPA Project)
- Once converted, again right click on the same project and you will see a “JPA TOOLS” in the context menu options.
- There you will see “Generate tables from entities” and few more options.
Now if you are using STS, you will wonder why you can not convert the given project to JPA project. In fact the option in configuration is missing itself. Then how can we convert the project??
No worries, it matter of installing few plugins that will make this feature available in your favourite IDE. Please follow them below.
- Move to Help (?) -> Install new software .
- Select your current version of eclipse. While writing this article, I am using Neon. It will fetch all the available software which you can install and improve your IDE.
(But make sure, you do not install those which you don’t need, otherwise your system will crawl.. 😛 )
- Move towards last and there you will find “Web, XML, Java EE and OSGi Enterprise Development“
- Expand that and select all the children having JPA as its title.
- Install and then restart the IDE.
We are done. Now convert the project to JPA and use the JPA Tool to generate entities and vice versa.
I hope this will help.