IntelliJ IDEA 15.0 Help

Creating Elements in Persistence Units

When a persistence unit is created, the next step is to populate it with entity classes, embeddables etc. Creating a persistence entity in a persistence unit results in creating the corresponding annotated Java class, and adding a node to the persistence unit.

You can create an entity in one of the following ways:

  • Using the context menu of the Persistence tool window.
  • Editing the persistence.xml file.
  • Creating an annotated Java class.

To create persistence elements

Do one of the following:

  • Right click a persistence unit node in the Persistence tool window, choose New on context menu, and then select the desired element from the submenu.
  • Open persistence.xml for editing, locate the code for the desired persistence unit, type an opening tag, and select the desired element from the suggestion list:

    Complete the package and class name. If a class doesn't exist, a quick fix will suggest to create it:

  • In the Project tool window, create a new Java class, and annotate it as @Entity. If the necessary annotation imports are missing, press Alt+Enter to show the list of imports.

    Select javax.persistence.Entity.

To create an entity bean

  1. Right-click a persistence unit node in the Persistence tool window, and choose New | Entity on context menu, and specify the metadata targets.
  2. Right-click the newly created entity bean to add new persistence fields.
  3. To generate/update Entities from a database, right-click the persistence unit, and choose Generate Persistence Mapping | By Database schema.
Last modified: 5 November 2015