Creating database tables from entities

Follow these steps to create database tables from entities and relationships that we have modeled:

  1. Right-click on the project and select JPA Tool | Generate Tables from Entities:
Figure 4.31: JPA Details for the courses field in Student entity
  1. Because we haven't configured any schema for our JPA project, the Schema drop-down will be empty. Click the Add a connection to JPA project link:
Figure 4.32: JPA project properties
  1. Click the Add connection link and create a connection to the course_management_jpa schema we created earlier. We have already seen how to create a connection to the MySQL schema in the Using Eclipse Data Source Explorer section of this chapter.
  2. Select course_management_jpa in the drop-down list shown in Figure 4.31 and click Next:
Figure 4.33: Schema Generation from entities
  1. Click Finish.

Eclipse generates DDL scripts for creating tables and relationships and executes these scripts in the selected schema. Once the script is run successfully, open the Data Source Explorer view (see the Using Eclipse Data Source Explorer section of this chapter) and browse tables in course_management_jpa connection. Make sure that tables and fields are created according to the entities we have created:

Figure 4.34: Tables created from JPA entities

This feature of Eclipse and JPA makes it very easy to update the database as you modify your entities.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.249.42