Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij Idea JPA console cannot run due '[3D000] No database selected'

I have a project with JPA module that correctly recognizes all entities. JPA Console and Persistence tool

Datasource is correctly set and it work well with autocomplete. I have not persistence.xml because I am using annotations.

I'm working a lot with @Query (native=false) on the repositories (extends CrudRepository) so using the JPA console it a really fast way to test queries. But when I try to run queries there I am getting:

[3D000] No database selected

I cannot use the USE reserved word there. So I am wondering what may be missing on my configuration.

like image 277
jfzr Avatar asked May 24 '18 20:05

jfzr


People also ask

How do I open the JPA structure in IntelliJ?

Open the JPA console in the toolbar or press Ctrl+Shift+F10 .

How does IntelliJ connect to Database?

To add a new database connection (called a data source in IntelliJ), open the Database window View -> Tool Windows -> Databases, then click the + sign and select Data Source and then MySQL from the sub-menu. The defaults for the MySQL connection should for a local install of MySQL.

How add JDBC jar to IntelliJ?

In the file browser, navigate to the JAR file of the JDBC driver, select it, and click OK. In the Class field, specify the value that you want to use for the driver . Click Apply.

Where is Database tool in IntelliJ?

In the Database tool window (View | Tool Windows | Database), you can work with databases and DDL data sources. You can view and modify data structures in your databases, and perform other associated tasks. To view a table, double-click the table.


1 Answers

I also struggled with this and found the solution.

When creating a datasource in IDEA, you can choose to which database you want to connect within that source. When left empty, no database is selected and you'll get the "[3D000] No database selected" error in the JPQL-console.

Instead, create a datasource with default database: add datasource

Now, assign this datasource in the Persistence tool window (e.g. View | Tool Windows | Persistence) to your persistence unit:

assign datasource

And:

assign datasource

Now, you should be ready to go!

enter image description here

like image 124
Bram Janssens Avatar answered Sep 25 '22 15:09

Bram Janssens