JPA learning - Lesson 7, Eclipse uses JPA Tools to reversely generate annotated entity classes

1. First establish a database connection in Eclipse
First open the Data Source Explorer window
write picture description here
and then right-click on the Database Connection to create a new link, enter here
write picture description here
I am using the mysql database, select and click Next
write picture description here
and then this panel will appear, click the button in the red circle to configure Driver
write picture description here
Then this pop-up window pops up. My driver is version 5.1. After selecting it, click JAP List
write picture description here
to remove the default driver, and then add the driver you have prepared. After selecting, click Properties to configure the database connection. :
write picture description here
After filling in the information, click OK to return to the previous pop-up window:
write picture description here
Here Drivers select the previously configured driver, and then click Test Connection to test whether the connection is successful. The pop-up window prompts that the connection is successful, and then click Finish.
2. Create a JPA project
New A JPA project
write picture description here
The specific steps are not explained in detail
3. Use JPA Tools to reversely generate entities Right-click
on the newly created JPA project and select Generate Entities From Tables in JPA Tools. A
write picture description here
pop-up window appears, and Connection selects the newly created one. Connection:
write picture description here
(You can also click the red circle button to recreate a new connection)
schamel select the database
table to select the table
and then click next to this pop-up window:
write picture description here
here is the annotation of the modified entity, for example:
The Key generator modifies the primary key generation strategy, select the identity to grow automatically
and click Finish to end.
write picture description here
Although it is a bit tedious to configure these, sometimes it is not as convenient to manually create a table with only a few fields. But in actual work, you often encounter tables with dozens or hundreds of fields. If you manually create entities at this time, it is estimated that you will be crazy...

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326692703&siteId=291194637