IntelliJ IDEA 2016.2 Help

Associating Data Sources with Session Factories and Persistence Units

If you are using JPA or Hibernate, you may want to associate your data sources with persistence units (in the case of JPA) or session factories (in the case of Hibernate). If you do so:

  • Your source code that references database tables will automatically be validated against the corresponding data source.
  • When using the JPA or Hibernate console, you won't need to additionally specify the database connection settings. The corresponding settings configured for the associated DB data source will automatically be used.

If the persistence units or session factories are generated by importing a database schema, the association between the corresponding persistence units or session factories and the data source is set automatically.

To associate a data source with a persistence unit or session factory

  1. Open the Persistence tool window (e.g View | Tool Windows | Persistence).
  2. Right-click the necessary module, persistence unit or session factory, and select Assign Data Sources in the context menu.
  3. In the Assign Data Sources dialog that opens, click the Data Source field and select the necessary data source. (To remove the association with the data source, select <none>.)
Last modified: 3 June 2016