Search code examples
javahibernatejpaintellij-ideacode-inspection

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


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?


Solution

  • 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!