简体   繁体   English

如何在 Spring Jpa 和 Intellij Idea 中删除数据源警告?

[英]How to remove data source warnings in Spring Jpa and Intellij Idea?

After new update Intellij, I have red warnings in entity classes.新更新 Intellij 后,我在实体类中有红色警告。 For example:例如:

@OneToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "poll_answers", joinColumns = @JoinColumn(name = "poll_id"))
    private Set<String> answers;

I have warning lines under "poll_answers" and "poll_id" "cannot resolve table/column" and offers me press "assign data source".我在“poll_answers”和“poll_id”下有警告行“无法解析表/列”并让我按“分配数据源”。

Your setup: Spring, JPA, ORM您的设置:Spring、JPA、ORM

Since your Spring project uses JPA and you are defining object-relational-mappings (ORM) using annotations:由于您的 Spring 项目使用 JPA,并且您正在使用注释定义对象关系映射 (ORM):

@JoinTable(name = "poll_answers", joinColumns = @JoinColumn(name = "poll_id"))

IntelliJ is intelligent and tries to validate the specified tables and columns against the database . IntelliJ 是智能的,它尝试根据数据库验证指定的

You can get an idea of the magic from this tutorial , although the topic is slightly going into another direction.您可以从本教程 中了解魔术,尽管该主题稍微转向了另一个方向。

You did not really provide the settings/setup (JPA Facet, etc.) that you are using within your IntelliJ project.您并未真正提供您在 IntelliJ 项目中使用的设置/设置(JPA Facet 等)。 It would be ideal if you can provide more information or a screenshot.如果您能提供更多信息或屏幕截图,那将是理想的。

Warning issue警告问题

Since you apparently have no database/data-source assigned within your IntelliJ Database Tools window, the above explained validation fails and the reported warning is shown:由于您的IntelliJ 数据库工具窗口中显然没有分配数据库/数据源,因此上述验证失败并显示报告的警告:

cannot resolve table/column无法解析表/列

Possible solution and further help可能的解决方案和进一步的帮助

A solution may be, to add the Data Source as the warning popup suggests already.一个解决方案可能是,按照警告弹出窗口的建议添加数据源

Maybe this tutorial can help you to setup a new Data Source within IntelliJ Database Tools .也许本教程可以帮助您在IntelliJ 数据库工具中设置新的数据源。 You can use your JDBC connetion-string (starting with jdbc:// ) from your mentioned application.properties to configure your database-connection.您可以使用您提到的application.propertiesJDBC 连接字符串(以jdbc://开头)来配置数据库连接。

In my comment to your question I also pointed you to this answer here, which pictorally describes how to Assign Data Sources via the IntelliJ menu: View -> Tool Windows -> Persistence .在我对您的问题的评论中,我还向您指出了这个答案,它以图解方式描述了如何通过 IntelliJ 菜单分配数据源View -> Tool Windows -> Persistence

If you want to ignore such warnings without having to configure a data-source inside IntelliJ you can do that by removing the particular inspection in Settings under : Editor > Inspections .如果您想忽略此类警告而不必在 IntelliJ 中配置数据源,您可以通过删除 Settings 下的特定检查来做到这一点: Editor > Inspections

The proper selector should be under: JPA > Unresolved database references in annotations正确的选择器应该在: JPA > Unresolved database references in annotations

在此处输入图片说明

Source: IDEs Support (IntelliJ Platform) 来源:IDE 支持(IntelliJ 平台)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM