IntelliJ IDEA 14.0.0 Web Help

Mapping by Database Schema

This section describes how to map data source to an object model using the database schema. After choosing Generate Persistence Mapping | By Database Schema , 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

  1. In the Persistence tool window, right-click the desired module with the JPA facet, or one of its persistence units, and choose Generate Persistence Mapping | By Database Schema on the context menu. The Import Database Schema dialog box appears.
  2. 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:
    jpaMapBySchema1.png
  3. In the Database Schema Mapping section, select the tables and fields to be included in the mapping:
    jpaMapBySchema2.png
  4. 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 add.png.
    In the Add 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 add.png 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.
  5. Define the target files to be generated. If you have invoked the Generate Persistence Mapping | By Database Schema 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 add.png, 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 icon_newXmlFile.png, and type the name of the new mapping file:

    jpaMapBySchema3.png

    If you want to define persistence using Java annotations, select the check box Generate JPA Annotations (Java 5).

  6. Click OK.

See Also

Last modified: 12 November 2014
comments powered by Disqus