Mapping by Database Schema
This section describes how to map data source to an object model using the database schema. After choosing , IntelliJ IDEA displays the Import Database Schema dialog, where you can choose to generate a mapping xml file, an annotated Java class, or both.
To define mapping by database schema
- In the Persistence tool window, right-click the desired module with the JPA facet, or one of its persistence units, and choose on the context menu. The Import Database Schema dialog box appears.
- In the General Settings section, specify the general mapping options (prefix and suffix of the new entity, the target package, etc.), and the database to be mapped. To do that, in the Choose Data Source field, click the ellipsis button, and select the desired database in the Data Sources dialog box:
- In the Database Schema Mapping section, select the tables and fields to be included in the mapping:
- If needed, create relationships between tables. To do that, in the Database Schema Mapping
section, select a table or one of its columns, and click .
In the Add / Edit Relationship dialog box, specify the tables for the both sides of the new relationship, attribute names and types on both sides, and join options.
To define the joint columns, click in the Join Columns section, and specify the columns in the source and target tables. Add as many column pairs as required and close the dialog box.
- Define the target files to be generated. If you have invoked the
command on a module node,
specify the persistence unit to which the generated mapping will be added.
If you want to define persistence using metadata, select the check box Generate Mapping XML, and specify the name of the xml mapping file. To do that, click , or press Shift+Enter, and specify the desired XML file name in the dialog that opens. If the desired file doesn't exist, select the directory where a mapping file will be created, click , and type the name of the new mapping file:
- Click OK.