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.
Choose Data Source
| When importing a database schema: Specify the data source to be used as a source of import. |
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. |
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. |
opens the dialog which lets you select the file. (The corresponding file must be available in the current project.)
| The destination package for your entity classes. |
opens the dialog which lets you select an existing package, or create a new one .
One or more characters to be used as a prefix for your entity class names.
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
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.
Create a new relationship between the entities. (The Add Relationship dialog will open.)
Edit the selected relationship. (The Edit Relationship dialog will open.)
Delete the selected relationship.
Refresh the database schema.
Select all the tables, fields and relationships.
Deselect all the tables, fields and relationships.
Expand all the nodes in the table.
Collapse all the nodes in the table.
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 . In the case of the persistence unit, just specify its name (a new
Generate Column Properties
Select the checkbox for the column properties (e.g.
Generate Single Mapping XML
| Store object/relational mappings for all the generated entity classes in one XML file. |
To define the target file:
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.