Spring DataJPA自定义查询问题: [英] Spring DataJPA custom query issue:
问题描述
我使用JPA(休眠+ PostgreSQL)和MongoDB进行了设置:
I have a setup with JPA (hibernate + postgresql) and MongoDB:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
我的存储库界面是:
@Repository
public interface JpaModelRepository extends JpaRepository<ModelEntity, Integer> {
public ModelEntity findByName(String modelNameSample);
}
我的实体:
@Entity
@Table (name = "model")
public class ModelEntity implements GenericId<Integer>, Serializable {
....
@Column (name = "name_tx")
private String name;
存储库接口的实现由SpringData自动生成.如果删除findByName,则在我的项目中一切正常.如果我将其保留在tomcat错误日志中,则为:
Implementation of the repository interface is auto-generated by SpringData. If I remove the findByName, all works fine in my project. If I leave it I have this in tomcat error log:
Caused by: java.lang.NoSuchMethodError: org.springframework.data.repository.query.parser.Part.getProperty()Lorg/springframework/data/repository/query/parser/Property;
at org.springframework.data.jpa.repository.query.JpaQueryCreator.toPredicate(JpaQueryCreator.java:163)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:95)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:49)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.<init>(PartTreeJpaQuery.java:102)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:59)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:93)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:164)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:71)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:269)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:142)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:114)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:38)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 85 more
试图使用此文档,但由于某些原因失败: Spring Doc
Tried to use this documentation but failed for some reason: Spring Doc
希望是设法创建自定义查询的人之一(例如findBySomeProperty(...))...
Hope is one of you guys managed to create a custom query (like findBySomeProperty(...)) ...
谢谢
推荐答案
我找到了答案:
<spring.version>3.1.2.RELEASE</spring.version>
<spring-data.jpa.version>1.2.0.BUILD-SNAPSHOT</spring-data.jpa.version>
<spring-data.mongodb.version>1.1.0.BUILD-SNAPSHOT</spring-data.mongodb.version>
https://github.com/SpringSource/spring-data-multistore-test
我在那个git仓库上做了一些Maven测试合并版本
I did some maven test combining version on that git repository
这篇关于Spring DataJPA自定义查询问题:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!