Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA highlights @Entity class names with "Cannot resolve symbol" in JPQL

IntelliJ IDEA highlights persistent @Entity class names with "Cannot resolve symbol" in red in JPQL which is distracting and buries real issues.

So, for example, I declare a query in my repository:

private static final String READ_BY_CANDIDATE_KEY = "SELECT cr FROM Entity AS cr left join cr.relationship AS re left join fetch cr.relationship2 WHERE re.candidateKey=:ID";

.. and "Entity" is underlined, even though "Entity" is a valid class name, and has the @Entity annotation. When the code actually runs, there are no problems.

I imagine some sort of configuration is required to let the IDE know what classes are valid? How is that configuration done?

Update: I do have a JPA facet, but it doesn't see the annotated classes. It seems to require a persistence.xml or orm.xml (which my project does not use)

like image 958
Simon Gibbs Avatar asked Sep 14 '12 08:09

Simon Gibbs


3 Answers

Seems like you have not selected the default JPA provider in facet configuration. Depending upon which provider you are using, pick one from the list. Available options are EclipseLink, Hibernate, OpenJPA, TopLink

like image 58
rajnish Avatar answered Nov 17 '22 04:11

rajnish


Make sure you have JPA or Hibernate facet configured in IntelliJ IDEA for your module.

like image 24
CrazyCoder Avatar answered Nov 17 '22 05:11

CrazyCoder


File -> Project Structure

At left pane select "Facets". If there is no JPA listed, click "+" sign and add "JPA"

At bottom of same dialog, at "Default JPA Provider", select - "Hibernate", press "OK"

If you have error at @Table annotation, configure and choose data source

Table name for select now should be recognized as entity class name

like image 3
GintsGints Avatar answered Nov 17 '22 05:11

GintsGints