I encountered a problem when doing project design today.
As shown in the figure above, use the JPA annotation @Query to customize the query, and report the error Can’t resolve symbol ‘Type’.
Solve problem 1 – not Working:
I checked a lot of information on the Internet and said that you can follow the following
File -> Project Structure -> Facets -> JPA -> select the ” + ” sign in the lower right corner -> persistence.xml
As shown in the figure below:
After adding, it may still report an error. Continue the following operations: File -> Invalidate Caches/Restart, which is actually to clear the cache and restart.
But after restarting it still reported the same error.
Solve problem 2 – it works
- The writing method of the JPA statement under the @Query annotation is different from the native SQL statement.
select t from Type tIt means to query all data from the table maintained by the Type entity class (using JPA to maintain the database table through the entity class, so you can query the data in the corresponding table through the Type entity class).
select entity class name from entity class entity class name.
- But the reason for the error here is actually a problem with the Hibernate mapping relationship. The from Xxx used in the hql query, Xxx is not the name of the entity class, but the EntityName (Hibernate annotation). If the EntityName is not explicitly specified after @Entity, the name of the entity class is used by default; if the EntityName is explicitly specified, when using hql query, the from EntityName should be used instead of the from entity class name.
- In my code, there are entity classes Tag, Type, Blog, etc., but the annotations all specify @Entity(name=”t_type”), etc., so the following methods should be used in the Dao layer:
The following is a screenshot of some code annotations in the entity class
- [Solved] IDEA2020 Error: Cannot resolve symbol ‘Servlet‘
- [Solved] JPA query data error: Page 1 of 0 containing UNKNOWN instances
- JPA multiple-data source startup error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘t
- HQL statement query error: could not resolve property [Solved]
- Android Studio Cannot resolve symbol [How to Solve]
- [Solved] Idea Build error. The symbol — Lombok cannot be found
- [Solved] IDEA java Cannot resolve method ‘getName‘ in ***
- Tomcat Run Error: Can‘t find catalina.jar [How to Solve]
- (error) READONLY You can‘t write against a read only replica.
- [Solved] JPA Create Sheet error at the First time: Cant DROP [xxx]；check that column/key exists
- [Solved] BASE64Encoder Error: Cannot resolve symbol ‘BASE64Encoder’
- [Solved] JPA sett in parameter error: Java.lang.illegalargumentexception
- How to Fix Error Caused by: java.util.MissingResourceException: Can‘t find bundle for base name xxx, locale zh_CN
- How to Solve Error executing DDL in JPA
- [Solved] ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed t
- [Solved] IDEA Import springboot Project Error: Cannot resolve plugin org.springframework.boot:spring-boot-maven-plugin:＜unknown＞
- IDEA springboot can recognize POM files, but suddenly it can’t reference mven dependencies. Strange things, inexplicable solutions
- [Solved] IDEA Maven Error: Cannot resolve xxx & Maven Dependencies Error
- Springdatajpa @query with like @param
- C# Bug Fixed InvalidCastException: Cannot cast from source type to destination type.