Unable to use JPA/Hibernate/SQL validation for Spring Boot @Entities

Answered

First, the context:

I have a very simple Spring Boot project (created with the Initialzr) and some @Entities (with @Entity, @Table and some @NamedQueries and @NamedNativeQueries). The Hibernate mappings are validated correctly at application startup against the database configured in application.properties (i.e. Spring Boot recognizes they are entities and knows how to talk to the database).

In Idea:

  • I also have a project-level datasource configured in Idea against the same database and all is well with it
  • The module has the JPA and Hibernate facets (no descriptors configured, since one doesn't exist as Spring Boot scans the project classes for @Entities), The module also has the Spring facet

The problem: with the @Entity class in the editor, there is no validation of the @Table name, @Column mappings or named queries. Nor is there navigation from the table/column name to the corresponding table/column in the Datasource view. It's as if Idea doesn't recognize the class as an @Entity; pressing Alt-Enter when inside the @Table name does not prompt for a data source to use for validation. I speculate this is due to the absence of an explicit persistence.xml or Hibernate mapping file, normal for Spring Boot apps.

I also went into the Persistence tab (where I can see one entry for JPA and Hibernate and I right-clicked each, then selected Assign Data Source but in both dialog the list of persistence units (or session factories, respectively) are empty.

Is the above a limitation of Idea? Or am I missing something?

Thanks and I can provide files if needed.

Idea is 2016.1.2

JL

 

 

Please sign in to leave a comment.