When JPA support for a module is enabled, persistence.xml file is created
in the META-INF directory under the module root. To persist Java objects to
a data source, you have to define persistence units.
IntelliJ IDEA enables you to populate persistence.xml file with persistence units,
using the context menu, or by editing the persistence.xml file.
The editor is aware of JPA specification and provides extensive coding assistance, which includes syntax and error highlighting, completion of tags, attributes and values, as well as intention actions and quick fixes.
This section describes how to create persistence units using the context menu or the editor.
- Open Persistence tool window.
- Right-click the desired module with JPA facet, and choose
on the context menu:

- In the New Persistent Unit dialog box, specify the name of the new persistent unit, or accept default. A
new persistence unit node is added to the module, and created in the
Persistence.xmlfile.By default, according to the JPA specification, a persistence unit in Java EE environment includes all the available annotated entities, which are displayed in the Persistence tool window. If you want a particular persistence unit to contain the entities that are unique to this unit only, in the editor add the
exclude-unlisted-classeselement with the valuetrueto the source code of the persistence unit.
- Open the
persistence.xmlfile for editing. - Start typing the
persistence-unittag, and see code completion in action:
- Type the name of the new persistence unit. Note that the corresponding persistence unit node is immediately created in the Persistence tool window.
Populate your persistence unit with elements, create relationships or get schema information from a data source.
See Also
Procedures:
- Auto-Completing Code
- Configuring Intention Actions
- Enabling JPA Support
- Generating Persistence Mappings
Reference: