IntelliJ IDEA 2017.1 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

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

/help/img/idea/2017.1/browseButton.png 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.

/help/img/idea/2017.1/browseButton.png 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.

/help/img/idea/2017.1/browseButton.png 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.

/help/img/idea/2017.1/browseButton.png opens the dialog which lets you select an existing package, or create a new one (/help/img/idea/2017.1/icon_newFolder.png).

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 check box 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.

ItemDescription
/help/img/idea/2017.1/new.png Create a new relationship between the entities. (The Add Relationship dialog will open.)
/help/img/idea/2017.1/edit1.png Edit the selected relationship. (The Edit Relationship dialog will open.)
/help/img/idea/2017.1/delete.pngDelete the selected relationship.
/help/img/idea/2017.1/refresh.png Refresh the database schema.
/help/img/idea/2017.1/iconSelectAllRemoteRunDialog.gif Select all the tables, fields and relationships.
/help/img/idea/2017.1/iconUnSelectAllRemoteRunDialog.gif Deselect all the tables, fields and relationships.
/help/img/idea/2017.1/expandAll.png Expand all the nodes in the table.
/help/img/idea/2017.1/collapseAll.png Collapse all the nodes in the table.

Generation Settings

ItemDescription
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 /help/img/idea/2017.1/new.png. 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 /help/img/idea/2017.1/icon_newXmlFile.png and specify the file name. .xml in the file name may be omitted.

Generate Column Properties Select the check box 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 /help/img/idea/2017.1/new.png.
  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 /help/img/idea/2017.1/icon_newXmlFile.png 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.

See Also

Last modified: 18 July 2017