Joh*_*n M 5 spring jpa spring-data
我正在使用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<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);
}
Run Code Online (Sandbox Code Playgroud)
当查询是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.<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
Run Code Online (Sandbox Code Playgroud)
显然,它曾经不被称为qwerty; 我只是重命名它来更好地说明这一点.
它似乎以@Query某种方式忽略了注释,并且它是应该定义要执行的查询的注释,并尝试基于方法名称来解释它.
我有什么想法我做错了吗?
geo*_*and 11
摘自Spring Data JPA(版本1.6.0.RELEASE)的文档:
@Query注释允许通过将nativeQuery标志设置为true来执行本机查询.请注意,我们当前不支持对本机查询执行分页或动态排序,因为我们必须操纵声明的实际查询,并且我们无法对本机SQL可靠地执行此操作.
很明显,本机查询不适用于分页.
因此,如果您绝对需要本机查询支持,则必须删除分页,或者您必须自定义自定义存储库实现,您将在其中自行实现该功能
| 归档时间: |
|
| 查看次数: |
5655 次 |
| 最近记录: |