我正在使用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)
Page
回到查询是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.301)
at org.springframework.data.repository.query.parser.PartTree.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)的文档:
原文链接:https://www.f2er.com/spring/431747.htmlThe @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.