Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate entities classes from database using Spring Boot and IntelliJ Idea?

I trying to make a project using the Spring Initializr wizard and I already have a database, so I want to generate entities classes using Spring Boot and IntelliJ Idea.

like image 647
Lucas León Avatar asked May 03 '16 04:05

Lucas León


1 Answers

Prerequisites are:

  1. You have your Spring Boot project initialized correctly in IDEA
  2. JPA persistence.xml file or similar has been generated correctly

Then you have to do these things:

  1. Create a DataSource - here you will add a simple DataSource that will connect to your database. The setup should be intuitive - you only provide connection details and add DB drivers (IDEA can download them for you)
  2. Add JPA/Hibernate facet. You can do it like this or this.
  3. Now you should be able to generate entities using IDEA. What you want to do here is choose Generate by Database Schema. The dialog will let you select the tables you want to use, the rest should be up to you.
like image 90
rapasoft Avatar answered Nov 01 '22 11:11

rapasoft