I have a project with JPA module that correctly recognizes all entities.
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.
Open the JPA console in the toolbar or press Ctrl+Shift+F10 .
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.
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.
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.
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:
Now, assign this datasource in the Persistence tool window (e.g. View | Tool Windows | Persistence) to your persistence unit:
And:
Now, you should be ready to go!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With