How to configure JPA with JPQL in Spring Boot Application - “can't resolve symbol..”

南笙酒味 提交于 2021-02-08 08:22:25

问题


I have a dependency spring-boot-starter-data-jpa

Configuration for JPA is inside application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/db?serverTimezone=UTC
spring.datasource.username=name
spring.datasource.password=pass
...

When I create @Entity:

@Entity
@Table(name="cats")
public class Cat {
    @Column(name="age")
    private int age;
    ....
}

It works well. When i try to use JPQL:

"select cat from Cat cat"

Intellij idea emphasizes it and says "Can't resolve symbol Cat", I click more "This inspection controls whether the Persistence QL Queries are error-checked".
It's worth saying it works correctly without errors and exceptions.

To solve it, somebody recommend in Intellij:

Project structure - facets - add - JPA.
After it Intellij stop to show this warning near JPQL syntax, but starts to show warnings near @Column(name="name") and @Table(name="cats") in my Entity.class.

How to configure JPA not to get this warnings neither in JPQL nor in Entity.class?


回答1:


Try using this:

"select cat from " + Cat.class.getName() + " cat"

This solution is quite good, because whenever you rename class Cat, intellij will rename it inside jpql query as well.



来源:https://stackoverflow.com/questions/54851818/how-to-configure-jpa-with-jpql-in-spring-boot-application-cant-resolve-symbo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!