How to avoid validation error "Cannot resolve column 'xy'" for embeddable classes in IntelliJ?
Asked Answered
W

1

5

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?

Weight answered 5/3, 2020 at 9:53 Comment(2)
Looks like youtrack.jetbrains.com/issue/IDEA-19017 For the inspection you can define a scope to run this inspection on, where you can exclude such classes.Hydrozoan
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.Weight
N
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!

Nester answered 17/6, 2020 at 10:59 Comment(1)
Nice solution! There's an open issue on IntelliJ's youtrack, about this problem. youtrack.jetbrains.com/issue/IDEA-223439 Maybe if they get some more requests the problem will be fixed.Foozle

© 2022 - 2024 — McMap. All rights reserved.