0

我有一个 JPA (hibernate + postgresql) 和 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 错误日志中有这个:

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

希望你们中的一个人设法创建了一个自定义查询(如 findBySomeProperty(...))...

谢谢

4

4 回答 4

1

Spring 数据 API 在 1.0 和 1.1 版本之间发生了更改,这就是此错误的原因。对您的两个依赖项使用相同的版本,它应该可以工作。

于 2012-09-21T13:04:17.280 回答
1

我有同样的问题

org.springframework.data.repository.query.parser.PartTree.isCountProjection()Ljava/lang/Boolean;

但是我通过使用适当的罐子组合来解决它

spring-data-jpa-1.2.0.RELEASE.jar <BR>
spring-data-commons-1.6.3.RELEASE.jar <BR>
spring-data-commons-core-1.4.1.RELEASE.jar<BR>
hibernate-entitymanager-4.1.12.final.jar<BR>
hibernate-jpa-2.1-api-1.0.0.final.jar<BR>
hibernate-validator-4.2.0.final.jar<BR>
hibernate-commons-annotations-4.0.0.CR2.jar<BR>

并使用 Spring core 3.2.5 版本的 jars。问题解决了。

我还使用了正确的方言,即连接到数据库的正确驱动程序。

于 2015-01-29T18:10:47.277 回答
0

我找到了答案:

    <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 测试组合版本

于 2012-09-21T23:49:50.873 回答
0

我在尝试使用 Spring Data JPA + Hibernate + Spring Framework 4.0 时遇到了同样的问题。问题是 Spring Data 项目没有跟上 Spring Framework 项目的速度。

我使用正确的 JAR 版本组合并排除任何其他 Spring 项目来解决问题,以便可以根据“Spring Data”pom.xml 文件正确并自动下载那些依赖的 JAR。在此处检查所有 Spring Data 依赖项:http ://search.maven.org/#artifactdetails%7Corg.springframework.data%7Cspring-data-jpa%7C1.6.0.RELEASE%7Cjar

我将我的 maven pom.xml 文件更改为:

    <properties>

    <!-- Generic properties -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <!-- Spring -->
    <spring-framework.version>3.2.9.RELEASE</spring-framework.version>
    <spring-data.version>1.6.0.RELEASE</spring-data.version>

    <!-- Hibernate / JPA -->
    <hibernate.version>3.6.10.Final</hibernate.version>

    <!-- Test -->
    <junit.version>4.11</junit.version>

    </properties>

    <dependencies>

    <!-- Spring framework -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>${spring-data.version}</version>
    </dependency>

    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>${hibernate-jpa.version}</version>
    </dependency>

            ....
</dependencies>
于 2014-05-23T08:38:48.250 回答