Persistence tool window
If you have at least one module with the JPA facet in your project, you can use the Persistence tool window. Based on the dependencies of your project, it can show the following elements:
JPA: view and manage JPA items: configuration files, persistence units, managed entities (persistent classes and fields), Spring repositories, and JPA converters.
Spring Data MongoDB: view MongoDB
@Document
classes, generate new classes and fields from MongoDB documents.Liquibase: view Liquibase changelogs, create new ones, and run Liquibase update.
Open Entity in Persistence view
In the gutter, click an entity icon . If you want to navigate to a particular field, click the corresponding icon next to it, such as or .
Select Select in Persistence View.
Alternatively, place the caret at your entity source code and click in the Persistence tool window.
Navigate to entity definitions
To navigate from an entity in the Persistence tool window to the corresponding source code definition in the editor, do one of the following:
Double-click a field.
Select a field or class and press F4.
Right-click a field or class and select Jump to Source.
View entity relationship diagrams (ERD)
Right-click a managed entity and select Entity Relationship Diagram.
Associate persistence units with data sources
Right-click a module, persistence unit, or entity, and select Assign Data Sources.
Select necessary data sources for relevant persistence units and click OK.
With this association, IntelliJ IDEA will validate the source code that references database tables against the corresponding data sources. Also, the JPA console will use proper database connection settings, and you won't need to specify them manually.
Associate persistence units with naming strategies
Right-click a module, persistence unit, or entity, and select Assign Naming Strategies.
Select necessary naming strategies for relevant persistence units and click OK.
Run JPQL queries
Right-click a persistence unit or entity and select JPA Console or click in the toolbar Ctrl+Shift+F10.
This will open the JPA console where you can write and execute JPQL queries.
Generate entities from database
With IntelliJ IDEA, you can create JPA entity classes and attributes based on an existing database schema. This functionality relies on the Reverse Engineering plugin, which is bundled in IntelliJ IDEA Ultimate.
Generate JPA entities from database
If a database connection is not established, create one.
In the Persistence tool window, expand the JPA node, right-click an element, and select .
Alternatively, right-click a database connection in the Database tool window, and select Create JPA Entities from DB.
Select a database connection, tables, and attributes to be mapped. For more information, refer to Entities from DB Wizard.
While your IDE is open, the database can be modified by other clients. To get the latest data from the database, you can click in either the Entities from DB window or in the Database tool window.
Generate attributes from database
You can also generate attributes for an existing class based on a database table.
If a database connection is not established, create one.
In the Persistence tool window, expand the JPA node, right-click an entity and select .
Alternatively, right-click a database connection in the Database tool window, and select Create JPA Attributes from DB.
Select a database connection, a table or a view, and columns to be mapped. The attributes migration flow is identical to what is described in the Entities from DB wizard section.
Generate @Document classes from MongoDB
With IntelliJ IDEA, you can create @Document
classes and attributes based on an existing collections in MongoDB. This functionality relies on the Reverse Engineering plugin, which is bundled in IntelliJ IDEA Ultimate.
Generate Document classes from MongoDB
If a MongoDB connection is not established, create one.
In the Persistence tool window, expand the Spring Data MongoDB node, right-click an element, and select .
Alternatively, right-click a MongoDB connection in the Database tool window, and select Create MongoDB Documents from DB.
Select a database connection, tables, and attributes to be mapped. For more information, refer to Entities from DB Wizard.
While your IDE is open, the database can be modified by other clients. To get the latest data from the database, you can click in either the Entities from DB window or in the Database tool window.
Generate attributes from MongoDB
You can also generate attributes for an existing class based on a MongoDB table.
If a database connection is not established, create one.
In the Persistence tool window, expand the Spring Data MongoDB node, right-click an entity and select .
Alternatively, right-click a MongoDB connection in the Database tool window, and select Create MongoDB Fields from DB.
Select a database connection, a table or a view, and columns to be mapped. The attributes migration flow is identical to what is described in the Entities from DB wizard section.