4

I'm using IntelliJ on a Java/Hibernate project. I've also assigned a data source to that project so most of the JPA validation errors for non existing columns are gone.

The only errors remaining are for these columns which are defined in @Embeddable classes like:

@Embeddable
public class MyEmbeddedClass {

    @Column(name="my_embedded_column")
    private String myEmbeddedColumn;

IntelliJ keeps warning me that these columns are not existing in the data model:

"Cannot resolve column 'my_embedded_column'"

Is there any way to make IntelliJ skip these JPA validation checks for @Embeddable classes without disabling the whole JPA validation functionality or am I supposed to create a bug ticket for the JPA validation plugin?

GreenTurtle
  • 1,144
  • 2
  • 21
  • 35
  • Looks like https://youtrack.jetbrains.com/issue/IDEA-19017 For the inspection you can [define a scope](https://www.jetbrains.com/help/idea/customizing-profiles.html) to run this inspection on, where you can exclude such classes. – Andrey Mar 05 '20 at 14:32
  • Thanks for pointing that issue in youtrack out - that's it! I've also tried to define a scope and configure the inspection accordingly but I cannot define a scope based on the content of a file (e.g. "not contains @Embeddable" or "contains @Entity"). And since my embeddable classes cannot be recognized by their package or name only there seems to be no way to get what I want. – GreenTurtle Mar 06 '20 at 07:37

1 Answers1

6

Same issue here. I've followd @Andrey suggestion and it worked for me. I've moved my @embeddable classes into a subpackage (org.mydomain.back.entities.ids). I've defined a scope, "MyCustomScope", exluding explicitly this subpackage. Then I've configured "Inspections-->JPA-->Unresolved databases references in annotations" like this:

Severity by Scope: - MyCustomScope (allButEmbeddedKeys): Checked and "Error". - Everywhere else: Unchecked.

It's more a workaround than an actual solution, because JPA inspection is disabled in such classes, with all inconveniences that could cause. But all errors in "embeddableId" classes are gone. Also for new classes defined into that subpackage. Hope it helps!

Leib
  • 106
  • 1
  • 6
  • 1
    Nice solution! There's an open issue on IntelliJ's youtrack, about this problem. https://youtrack.jetbrains.com/issue/IDEA-223439 Maybe if they get some more requests the problem will be fixed. – funder7 Jul 06 '20 at 19:53