首页 > 解决方案 > Intellij Idea JPA 控制台由于“[3D000] 未选择数据库”而无法运行

问题描述

我有一个带有 JPA 模块的项目,可以正确识别所有实体。 JPA 控制台和持久性工具

数据源已正确设置,并且可以很好地使用自动完成功能。我没有persistence.xml,因为我正在使用注释。

我在存储库(扩展 CrudRepository)上使用 @Query (native=false) 进行了很多工作,因此使用 JPA 控制台是测试查询的一种非常快速的方法。但是当我尝试在那里运行查询时,我得到:

[3D000] No database selected

我不能在那里使用 USE 保留字。所以我想知道我的配置中可能缺少什么。

标签: javajpaintellij-idea

解决方案


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


推荐阅读