IntelliJ IDEA 2024.3 Help

Database Connections

JPA Structure panel is responsible for everything related to DB configurations. To create a new DB connection, click Add and select DB Connection. To use Reverse Engineering and Database Versioning features, the first thing you will need to do is create a database connection.

For now, JPA Buddy supports the following databases:

Automatic Detection of Data Source Configurations

JPA Buddy offers a convenient way to automatically detect data source configurations from the *.properties file and fills in the required connection settings for you.

jpa-structure-db-connection

To use this feature, click on the Detect Connections button in the JPA Structure tab, and JPA Buddy will automatically populate the corresponding fields.

ij-ultimate-data-sources

Starting from version 2023.2, JPA Buddy seamlessly integrates with IntelliJ IDEA Ultimate's robust options for data source configurations. For more information, refer to the relevant JetBrains documentation page.

JPA Buddy provides a similar mechanism for the IntelliJ IDEA Community edition.

ij-community-db-connection

It’s worth noting that JPA Buddy is compatible with any property file that adheres to the standard naming convention for property files. This includes YAML files, environment-specific properties files, test-specific properties files, and more. For example, application.properties, application-test.properties, application.yaml, application-prod.yaml.

Automatic Generation of Property Files

Additionally, JPA Buddy can help you generate *.properties files based on your data source configuration. This feature will save you time and effort in configuring your application.

To do so, open the relevant property file, then access the Generate menu by pressing Alt+Insert. Select the Data source option from the menu.

generate-menu-db-connection

This will open the Data Source window, as shown in the screenshot below.

data-source-db-connection

From the Data Source window, select the appropriate data source for your application. You can choose the DDL auto mode you need in the drop-down menu below. Additionally, there are two other options available in the Data Source window: 'Show SQL' and 'Format SQL'. These options allow you to choose whether to show SQL statements that are executed by Hibernate on your standard output for debugging purposes and whether to format those statements for readability, respectively. Once you have selected the data source and any other options you need, JPA Buddy will fill in the selected property file with the necessary configuration for you.

Non-Default Schema Connection

Some RDBMSs that JPA Buddy supports provide the possibility to create non-default schemas, but not all of them work well with JDBC. That's why you may encounter some known issues when generating diffs or reverse engineering. For now, these issues can only be solved with some workaround. Below are examples of connecting to non-default schemas for all databases supported by JPA Buddy.

PostgreSQL

The default PostgreSQL schema is public. For other schemes you need to specify desired schema name in the Connection params field via currentSchema parameter:

ij-community-postgres
ij-ultimate-postgres

Microsoft SQL Server

The default Microsoft SQL Server schema is dbo. To connect to the non-default scheme in Microsoft SQL Server, you should follow the steps described below:

  1. Create a login:

    create login JohnDoe with password='saPassword1'
  2. Create a user with a default schema from which you want to create an entity:

    create user JohnDoe for login JohnDoe with default_schema = my_schema
  3. Give it owner rights:

    exec sp_addrolemember 'db_owner', 'JohnDoe'
  4. Create a new connection with the newly created user’s credentials and add a schema name in the database URL field

For JDBC the connection setup will look like this:

ij-community-mssql-jdbc
ij-ultimate-mssql-jdbc

And for JTDS like this:

ij-community-mssql-jtds
ij-ultimate-mssql-jtds

Oracle

In Oracle, schema, user and database are the same thing. Hence, to connect to the non-default scheme you need to specify its schema name in the user field.

For the connection via SID setup will look like this:

ij-community-oracle-sid
ij-ultimate-oracle-sid

And for the connection via service name like this:

ij-community-oracle-service
ij-ultimate-oracle-service

MySQL & MariaDB

To connect to the non-default scheme you need to specify the schema name in the Database URL field:

ij-community-mysql
ij-ultimate-mysql

Database Drivers

Since IntelliJ IDEA CE doesn't allow configuring database drives, JPA Buddy is to the rescue! Open Tools -> JPA Buddy -> Database Drivers window. Here you can configure drivers for each supported RDBMS by selecting one of the proposed driver versions and adding additional files from your local machine.

database-drivers
Last modified: 14 March 2024