Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 将@Query切换到nativeQuery会导致PropertyReferenceException_Spring_Jpa_Spring Data - Fatal编程技术网

Spring 将@Query切换到nativeQuery会导致PropertyReferenceException

Spring 将@Query切换到nativeQuery会导致PropertyReferenceException,spring,jpa,spring-data,Spring,Jpa,Spring Data,我将SpringJPA与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.reposito

我将SpringJPA与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<Event, UUID> {
    @Query(value = "Select * From event Where ST_Intersects(ST_SetSRID(ST_MakeBox2D(ST_MakePoint(:swLongitude, :swLatitude), ST_MakePoint(:neLongitude, :neLatitude)), 4326), location)", nativeQuery = true)
    Page<Event> qwerty(@Param("swLatitude") double swLatitude, @Param("swLongitude") double swLongitude, @Param("neLatitude") double neLatitude, @Param("neLongitude") double neLongitude, Pageable pageable);
}
显然,它过去不叫qwerty;为了更好地说明这一点,我将其重命名

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


你知道我做错了什么吗?

摘自SpringDataJPA(版本1.6.0.RELEASE)的文档:

@Query注释允许通过设置 nativeQuery标志设置为true。请注意,我们目前不支持 如我们所愿,对本机查询执行分页或动态排序 必须操作实际声明的查询,而我们不能这样做 为本机SQL提供可靠的支持

很明显,本机查询不能与分页一起工作


因此,如果您确实需要本机查询支持,您将不得不放弃分页,或者您必须修改一个自定义存储库实现,在该实现中您将自己实现该功能

感谢您快速而正确的响应,我应该仔细阅读。不过,该错误消息本可以更方便用户使用。@geo和仅供参考,我们创建该错误消息是为了在这种情况下创建一条更合理的异常消息。
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property qwerty found for type Event!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76)
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:213)
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:321)
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:301)
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:82)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:60)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$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.<init>(RepositoryFactorySupport.java:320)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:169)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.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