IntelliJ IDEA 2018.2 Help

Generate Persistence Mapping - Import dialogs

From the Persistence tool window: Right-click a module, persistence unit or session factory, point to Generate Persistence Mapping and select the necessary option.


Specify the settings for generating entity classes and object/relational mappings for them. Depending on the option that you selected, one of the following is used as a source:

  • A database schema represented by a data source.

  • An EJB facet, if exists in the current project, or, to be more exact, the deployment descriptor file ejb-jar.xml associated with that facet. (Only the <entity> elements are processed.)

  • Only for JPA: a Hibernate object/relational mapping file (.hbm.xml). The file should be within the current project.

General Settings

Item

Description

Choose Data Source

When importing a database schema: Specify the data source to be used as a source of import.

browseButton opens the Data Sources and Drivers dialog which lets you create a new data source.

Choose EJB Facet

When importing an EJB facet: Specify the EJB facet to be used as a source.

browseButton opens the dialog which lets you select the facet. (The EJB facets available in the current project are suggested.)

Choose Hibernate XML

When importing a Hibernate object/relational mapping file: Specify the .hbm.xml file to be used as a source.

browseButton opens the dialog which lets you select the file. (The corresponding file must be available in the current project.)

Package

The destination package for your entity classes.

browseButton opens the dialog which lets you select an existing package, or create a new one (icons actions newFolder svg).

Entity prefix

One or more characters to be used as a prefix for your entity class names.

Entity suffix

One or more characters to be used as a suffix for your entity class names.

Prefer primitive types

When importing a database schema: Prefer primitive field types to object types (e.g. when int and java.lang.Integer are the alternatives).

Show default relationships

When importing a database schema: If this checkbox is selected, IntelliJ IDEA analyzes the foreign keys in the tables and suggests to create corresponding relationships (e.g. one-to-one, one-to-many).

Database Schema Mapping

This section is available only when importing a database schema.

Select the tables and columns to be mapped. Edit the names of the entity classes and their persistent fields (the Map As column). Adjust the field types (the Mapped Type column). Use the toolbar for working with relationships and performing other tasks.

Item

Description

icons general add svg

Create a new relationship between the entities. (The Add Relationship dialog will open.)

icons actions edit svg

Edit the selected relationship. (The Edit Relationship dialog will open.)

icons general remove svg

Delete the selected relationship.

icons actions refresh svg

Refresh the database schema.

iconSelectAllRemoteRunDialog

Select all the tables, fields and relationships.

iconUnSelectAllRemoteRunDialog

Deselect all the tables, fields and relationships.

icons actions expandall svg

Expand all the nodes in the table.

icons actions collapseall svg

Collapse all the nodes in the table.

Generation Settings

Item

Description

Add to Persistence Unit / Add to Session Factory

The persistence unit or session factory with which the generated entity classes will be associated.

If the Generate Persistence Mapping command was called on a persistence unit or session factory, the info about the entity classes will be added to the current persistence unit or session factory (hibernate.cfg.xml).

If the command was called on a module, you can select a target persistence unit or session factory. This may be an existing persistence unit or session factory (hibernate.cfg.xml), or a new one. To create a new persistence unit or session factory, click icons general add svg. In the case of the persistence unit, just specify its name (a new <persistence-unit name=""/> element will be added to persistence.xml.) In the case of the session factory, a new Hibernate configuration file will be created. So, in the dialog that opens, select the destination folder, click icon newXmlFile and specify the file name. .xml in the file name may be omitted.

Generate Column Properties

Select the checkbox for the column properties (e.g. length, nullable) to be included.

Generate Single Mapping XML

Store object/relational mappings for all the generated entity classes in one XML file.

To define the target file:

  1. Click icons general add svg.

  2. If suggested, select the target file format (Hibernate mapping or JPA mapping descriptor (JPA ORM)).

  3. In the dialog that opens, select an existing mapping file or create a new one.

    To create a new file, select the destination directory, click icon newXmlFile and specify the file name. .xml in the file name may be omitted.

Generate Separate XML per Entity

Create an individual object/relational mapping file for all the generated entity classes. The file names will be <ClassName>.xml for JPA and <ClassName>.hbm.xml for Hibernate.

Generate JPA Annotations (Java 5)

Add the mapping information to the source code of the generated entity classes as annotations.

Last modified: 20 November 2018

See Also