IntelliJ IDEA 2018.1 Help

Enabling Hibernate Support

Overview

To be able to use Hibernate support, you should:

  • Make sure that the Hibernate Support plugin is enabled. (This plugin is bundled with the IDE and enabled by default.)
  • Enable Hibernate support at a module level. You can do that when creating a new project or module. You can also enable Hibernate support for an existing module. In all such cases, IntelliJ IDEA will (some of the following will be offered as options):
    • Create a Hibernate configuration file hibernate.cfg.xml and a class with a main() method that outputs the records for your managed entities.
    • Download the library files that implement the framework and add them to the dependencies of the corresponding module.
    • Generate entity classes and object/relational mappings for your database tables (if you have an appropriate data source available).
    • Create a Hibernate facet. You'll be able to use that facet for managing your configuration hibernate.cfg.xml files.
    • Make the Persistence tool window available.

Making sure that the Hibernate Support plugin is enabled

  1. Open the Settings / Preferences dialog (e.g. Ctrl+Alt+S).
  2. In the left-hand part of the dialog, select Plugins.
  3. In the right-hand part of the dialog, on the Plugins page, type hib in the search box. As a result, only the plugins whose names and descriptions contain hib are shown.
  4. If the checkbox to the right of Hibernate Support is not selected, select it.
  5. Click OK.
  6. If suggested, restart IntelliJ IDEA.

Enabling Hibernate 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. In the right-hand part of the page, specify the JDK that you are going to use.
  3. Under Additional Libraries and Frameworks, select the Hibernate checkbox.
  4. If necessary, select to create a configuration file (hibernate.cfg.xml) and a main class (a class with a main() method that outputs the records for your managed entities).

    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 entity classes and object/relational mappings for them.

  5. Select the required library option and, if necessary, specify the associated settings. You can choose to:
    • Download Hibernate 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.

If you selected to import a database schema, the Import Database Schema dialog opens, and you can specify the entity classes to be generated and associated settings.

Enabling Hibernate 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 Hibernate checkbox.
  3. If necessary, select to create a configuration file (hibernate.cfg.xml) and a main class (a class with a main() method that outputs the records for your managed entities).

    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 entity classes and object/relational mappings for them.

  4. Select the required library option and, if necessary, specify the associated settings. You can choose to:
    • Download Hibernate 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.

If you selected to import a database schema, the Import Database Schema dialog opens, and you can specify the entity classes to be generated and associated settings.

Last modified: 24 July 2018

See Also