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
- Enabling JPA support when creating a project or module
- Enabling JPA support for an existing module
- Open the Preferences dialog (e.g. ⌘, or ⌘,⌘, or ⌘,⌘, or ⌘,⌥ F7, ⌥F7 or ⌥F7^ ⌥ S, ⌃⌥S or ⌃⌥S).
- In the left-hand part of the dialog, under IDE Settings, select Plugins.
-
In the right-hand part of the dialog, on the Plugins page,
type
jpin the search box. As a result, only the plugins whose names and descriptions containjpare shown in the list of plugins. - If the check box to the right of Java EE: EJB, JPA, Servlets is not selected, select it.
- Click OK in the Preferences dialog.
- If suggested, restart IntelliJ IDEA.
-
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.
-
If you are going to create a new project:
click Create New Project on the Welcome screen or
select File | New | Project.
- 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).
- Select the JavaEE Persistence check box.
-
Select the version of
persistence.xmlto be created. (persistence.xmlis a JPA configuration file.)If necessary, select the Java persistence provider. (This setting affects the
<provider>element inpersistence.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.
-
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 ^ 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.
-
Download JPA implementation files and arrange those files in a library.
-
Specify the name and location settings. For more information,
see Project Name and Location or Module Name and Location.
Click Finish.
If you selected to import a database schema, the Import Database Schema dialog will open, and you'll be able to specify the JPA entity classes to be generated and associated settings.
- In the Project tool window, right-click the necessary module and select Add Framework Support.
- In the left-hand pane of the Add Frameworks Support dialog that opens, select the JavaEE Persistence check box.
-
Select the version of
persistence.xmlto be created. (persistence.xmlis a JPA configuration file.)If necessary, select the Java persistence provider. (This setting affects the
<provider>element inpersistence.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.
-
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 ^ 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.
-
Download JPA implementation files and arrange those files in a library.
- Click OK.
If you selected to import a database schema, the Import Database Schema dialog will open, and you'll be able to specify the JPA entity classes to be generated and associated settings.
See Also
Procedures:
- Configuring Module Dependencies and Libraries
- Creating Persistence Units
- Generating Persistence Mappings
Reference:
Concepts:
External Links:
