Creating Persistence Units
When JPA support for a module is enabled,
persistence.xml file is created
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
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.
To create a persistence unit using the context menu
- 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
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 value
trueto the source code of the persistence unit.
To create a persistence unit in the editor
- 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.