如何在Spring Boot应用程序中使用JPQL配置JPA-“无法解析符号." [英] How to configure JPA with JPQL in Spring Boot Application - "can't resolve symbol.."

查看:202
本文介绍了如何在Spring Boot应用程序中使用JPQL配置JPA-“无法解析符号."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个依赖项spring-boot-starter-data-jpa

JPA的配置位于 application.properties 中:

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
...

当我创建 @Entity:

When I create @Entity:

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

效果很好.当我尝试使用 JPQL 时:

It works well. When i try to use JPQL:

"select cat from Cat cat"

Intellij想法强调了这一点,并说出 无法解析符号Cat" ,我点击了 more "检查控制是否对持久性QL查询进行了错误检查". .
值得一提的是,它没有错误例外正常运行.

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.

要解决此问题,有人在 Intellij 中推荐:

To solve it, somebody recommend in Intellij:

项目结构-方面-添加-JPA .
Intellij 停止 后,在 JPQL 语法附近显示此警告,但 开始 在我的 中的 @Column(name ="name") @Table(name ="cats")附近显示警告> Entity.class .

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.

如何配置JPA 既不在JPQL中也不在Entity.class中获取此警告 ?

推荐答案

尝试使用此功能:

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

此解决方案非常好,因为每当您重命名类Cat时,intellij也会在jpql查询中重命名它.

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

这篇关于如何在Spring Boot应用程序中使用JPQL配置JPA-“无法解析符号."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆