[IDEA Usage Guide] How to automatically generate entity models from database tables in Java projects using the Hibernate framework?

[IDEA Usage Guide] How to automatically generate entity models from database tables in Java projects using the Hibernate framework?

Step 1: Find and open the "Persistence" toolbar.

As shown in the figure below, find "View -> Tool Windows -> Persistence" and click "Persistence".
Insert image description here

Step 2: Find and open the "Import Database Schema" window.

The persistence configuration toolbar "Persistence" will pop up in the lower left corner of the development tool, as shown in the figure below. After clicking, there will be a pop-up box. Find the project name in the pop-up box (for example, the project name in this example is first-hibernate-project), then right-click and select "Generate Persistence Mapping -> By Database Schema" to open "Import Database Schema” window.
Insert image description here
Insert image description here

Remark:

  1. In the picture above, if there is no option for "Choose Data Source", it means that the connection data source has not been configured yet. You can refer to the article to configure it first: [IDEA User Guide] How to use the IDEA development tool as a visual tool to operate the database?

  2. After the configuration is completed, if you don't know how to return to the operation interface of the "Import Database Schema" window above, you can refer to the article: [IDEA
    Usage Guide] How to find and open the "Import Database Schema" window for Java projects using the Hibernate framework?

Step 3: Configure data source information

Configure data source information in the "Import Database Schema" window. Configuration information includes selecting the database, configuring the corresponding package, and selecting the corresponding data table, as shown in the figure below.
Insert image description here
After the configuration is completed, click the "OK" button in the lower right corner, and a prompt box will pop up, as shown in the figure below. Just click the "Yes" button.
Insert image description here

Step 4: View the automatically generated solid model.

As you can see, the IDEA development tool automatically generates the entity model corresponding to the data table, as shown in the figure below.
Insert image description here

appendix

The generated entity model (TblAccountEntity) is as follows:

package 

Guess you like

Origin blog.csdn.net/Shipley_Leo/article/details/130783373
Recommended