简体   繁体   中英

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

After new update Intellij, I have red warnings in entity classes. 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".

Your setup: Spring, JPA, ORM

Since your Spring project uses JPA and you are defining object-relational-mappings (ORM) using annotations:

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

IntelliJ is intelligent and tries to validate the specified tables and columns against the database .

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. 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:

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 . You can use your JDBC connetion-string (starting with jdbc:// ) from your mentioned application.properties to configure your database-connection.

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 .

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 .

The proper selector should be under: JPA > Unresolved database references in annotations

在此处输入图片说明

Source: IDEs Support (IntelliJ Platform)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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