IntelliJ IDEA 14.0.0 Web Help

Enabling JPA Support

To be able to use JPA support, you should:

  • Make sure that the Java EE: EJB, JPA, Servlets plugin is enabled. This plugin is bundled with the IDE and enabled by default. However, you may have disabled it for some reason by now.
  • Enable JPA support at a module level. You can do that when creating a new project, or when adding a new module to an existing project. You can also enable JPA support for an existing module.

On this page:

Making sure that the Java EE: EJB, JPA, Servlets plugin is enabled

  1. Open the Settings dialog (e.g. Ctrl+Alt+S).
  2. In the left-hand part of the dialog, under IDE Settings, select Plugins.
  3. In the right-hand part of the dialog, on the Plugins page, type jp in the search box. As a result, only the plugins whose names and descriptions contain jp are shown in the list of plugins.
  4. If the check box to the right of Java EE: EJB, JPA, Servlets is not selected, select it.
  5. Click OK in the Settings dialog.
  6. If suggested, restart IntelliJ IDEA.

Enabling JPA support when creating a project or module

  1. Do one of the following:
    • If you are going to create a new project: click Create New Project on the Welcome screen or select File | New Project.

      As a result, the New Project wizard opens.

    • If you are going to add a module to an existing project: open the project you want to add a module to, and select File | New Module.

      As a result, the New Module wizard opens.

  2. On the first page of the wizard, in the left-hand pane, select Java Enterprise. In the right-hand part of the page, specify the JDK to be used and select the Java EE version to be supported. If necessary, specify the application server you are going to deploy your application to (e.g. to test the application behavior).
  3. Select the JavaEE Persistence check box.
  4. Select the version of persistence.xml to be created. (persistence.xml is a JPA configuration file.)

    If necessary, select the Java persistence provider. (This setting affects the <provider> element in persistence.xml. For example, <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> will be generated for EclipseLink. There will be no <provider> element if <no provider> is selected.)

    If there is a database defined in IntelliJ IDEA as a data source, you can select to import the database schema. This will result in creating the necessary JPA entity classes and persistence metadata.

  5. Select the required library option and, if necessary, specify the associated settings. You can choose to:
    • Download JPA implementation files and arrange those files in a library.

      To do that, under Libraries, select Download. Optionally, click Configure to edit the library settings. (The Downloading Options dialog will open.)

    • Use a library that is already defined IntelliJ IDEA.

      To do that, click Use library and select the required library from the list. Optionally, click Configure to edit the library settings. (The Edit Library dialog will open.)

    • Create a new library using the appropriate JAR files available on your computer.

      To do that, click Use library and then click Create. Select the required JAR files in the dialog that opens. (For multiple selection, keep the Ctrl key pressed.) Optionally, click Configure to edit the library settings. (The Create Library dialog will open.)

    • Postpone setting up the library until a later time. In this case, select Set up library later.

    Click Next.

  6. Specify the name and location settings. For more information, see Project Name and Location or Module Name and Location.

    Click Finish.

Enabling JPA support for an existing module

  1. In the Project tool window, right-click the necessary module and select Add Framework Support.
  2. In the left-hand pane of the Add Frameworks Support dialog that opens, select the JavaEE Persistence check box.
  3. Select the version of persistence.xml to be created. (persistence.xml is a JPA configuration file.)

    If necessary, select the Java persistence provider. (This setting affects the <provider> element in persistence.xml. For example, <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> will be generated for EclipseLink. There will be no <provider> element if <no provider> is selected.)

    If there is a database defined in IntelliJ IDEA as a data source, you can select to import the database schema. This will result in creating the necessary JPA entity classes and persistence metadata.

  4. Select the required library option and, if necessary, specify the associated settings. You can choose to:
    • Download JPA implementation files and arrange those files in a library.

      To do that, under Libraries, select Download. Optionally, click Configure to edit the library settings. (The Downloading Options dialog will open.)

    • Use a library that is already defined IntelliJ IDEA.

      To do that, click Use library and select the required library from the list. Optionally, click Configure to edit the library settings. (The Edit Library dialog will open.)

    • Create a new library using the appropriate JAR files available on your computer.

      To do that, click Use library and then click Create. Select the required JAR files in the dialog that opens. (For multiple selection, keep the Ctrl key pressed.) Optionally, click Configure to edit the library settings. (The Create Library dialog will open.)

    • Postpone setting up the library until a later time. In this case, select Set up library later.
  5. Click OK.

See Also

Last modified: 12 November 2014
comments powered by Disqus