3

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

halfer
  • 19,824
  • 17
  • 99
  • 186
andrew17
  • 851
  • 2
  • 10
  • 25

2 Answers2

4

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

enter image description here

Source: IDEs Support (IntelliJ Platform)

Dario
  • 208
  • 2
  • 10
2

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
hc_dev
  • 8,389
  • 1
  • 26
  • 38
  • Do so, if you want to learn how to take advantage of these warnings! As [P.J. Meisch commented](https://stackoverflow.com/questions/59127293/spring-jpa-intellij-entity-class-red-warns-under-fields-types-sources/59146149#comment104549677_59127293) you can also ignore or disable warnings and your application will compile and run anyway. – hc_dev Dec 03 '19 at 20:23
  • it compiles fine even with them. But i dont like to see that red warning. If that was yellow... . – andrew17 Dec 03 '19 at 21:53