加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

spring – 将@Query切换为nativeQuery会导致PropertyReferenceE

发布时间:2020-12-15 01:38:53 所属栏目:大数据 来源:网络整理
导读:我正在使用Spring JPA和Hibernate PostgreSQL的. 我有以下JPA存储库: import org.springframework.data.domain.Page;import org.springframework.data.domain.Pageable;import org.springframework.data.jpa.repository.JpaRepository;import org.springfra

我正在使用Spring JPA和Hibernate& PostgreSQL的.

我有以下JPA存储库:

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.UUID;

public interface EventRepository extends JpaRepository

回到查询是HQL并且没有将nativeQuery设置为true时,它工作正常.现在我需要转移到本机SQL查询,虽然添加nativeQuery = true并重写查询将解决它.

但是,我现在得到:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property qwerty found for type Event!
at org.springframework.data.mapping.PropertyPath.

显然,它曾经不被称为qwerty;我只是重命名它来更好地说明这一点.

它似乎以某种方式忽略了@Query注释,并且它是应该定义要执行的查询的注释,并尝试基于方法名称来解释它.

我有什么想法我做错了吗?

最佳答案
摘自Spring Data JPA(版本1.6.0.RELEASE)的文档:

The @Query annotation allows to execute native queries by setting the
nativeQuery flag to true. Note,that we currently don’t support
execution of pagination or dynamic sorting for native queries as we’d
have to manipulate the actual query declared and we cannot do this
reliably for native SQL.

很明显,本机查询不适用于分页.

因此,如果您绝对需要本机查询支持,则必须删除分页,或者您必须自定义自定义存储库实现,您将在其中自行实现该功能

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读