我正在使用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 JpaRepositoryBox2D(ST_MakePoint(:swLongitude,:swLatitude),ST_MakePoint(:neLongitude,:neLatitude)),4326),location)",nativeQuery = true)
Pagearam("swLatitude") double swLatitude,@Param("swLongitude") double swLongitude,@Param("neLatitude") double neLatitude,@Param("neLongitude") double neLongitude,Pageable pageable);
}
回到查询是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.createqueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:91)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:168)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:69)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.factorybeanSupport.initAndReturn(RepositoryfactorybeanSupport.java:224)
at org.springframework.data.repository.core.support.RepositoryfactorybeanSupport.afterPropertiesSet(RepositoryfactorybeanSupport.java:210)
at org.springframework.data.jpa.repository.support.JpaRepositoryfactorybean.afterPropertiesSet(JpaRepositoryfactorybean.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.invokeInitMethods(AbstractAutowireCapablebeanfactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.initializeBean(AbstractAutowireCapablebeanfactory.java:1549)
... 34 more
显然,它曾经不被称为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.
原文地址:https://www.jb51.cc/spring/431747.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。