2016-06-13 180 views
3

我試圖使用QueryDslPredicateExecutor與MongoDB和Spring-Data,但它似乎窒息的「存在( )「財產。「找不到屬性類型」...當使用QueryDslPredicateExecutor與MongoDB和Spring-Data

我使用 -

org.springframework.boot:spring-boot-starter-parent:1.3.5.RELEASE 
com.querydsl:querydsl-mongodb:4.1.2 
com.querydsl:querydsl-apt:4.1.2 
org.mongodb.morphia:morphia:1.1.1 

堆棧跟蹤

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property exists found for type Tree! 
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:353) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:84) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.mongodb.repository.query.PartTreeMongoQuery.<init>(PartTreeMongoQuery.java:60) ~[spring-data-mongodb-1.9.0.RELEASE.jar:na] 
    at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory$MongoQueryLookupStrategy.resolveQuery(MongoRepositoryFactory.java:168) ~[spring-data-mongodb-1.9.0.RELEASE.jar:na] 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:435) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:220) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:266) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:252) ~[spring-data-commons-1.12.0.RELEASE.jar:na] 
    at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:108) ~[spring-data-mongodb-1.9.0.RELEASE.jar:na] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE] 
    ... 30 common frames omitted 

異常正從該類

package org.springframework.data.mapping 
// PropertyPath.class 
.... 

/** 
* Creates a leaf {@link PropertyPath} (no nested ones with the given name and owning type. 
* 
* @param name must not be {@literal null} or empty. 
* @param owningType must not be {@literal null}. 
* @param base the {@link PropertyPath} previously found. 
*/ 
PropertyPath(String name, TypeInformation<?> owningType, List<PropertyPath> base) { 

    Assert.hasText(name, "Name must not be null or empty!"); 
    Assert.notNull(owningType, "Owning type must not be null!"); 
    Assert.notNull(base, "Perviously found properties must not be null!"); 

    String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name); 
    TypeInformation<?> propertyType = owningType.getProperty(propertyName); 

    if (propertyType == null) { 
     throw new PropertyReferenceException(propertyName, owningType, base); 
    } 

    this.owningType = owningType; 
    this.isCollection = propertyType.isCollectionLike(); 
    this.type = propertyType.getActualType(); 
    this.name = propertyName; 
} 

的性質(方法)拋出從QueryDslPredicateExecutor未來我的Repository擴展的類。

public abstract boolean org.springframework.data.querydsl.QueryDslPredicateExecutor.exists(com.querydsl.core.types.Predicate) 

這裏是倉庫 -

public interface TreeRepository extends ExtendedMongoRepository<Tree, String>, QueryDslPredicateExecutor<Tree>{} 
+0

看來這是由於存儲庫直接擴展了基本接口而不是MongoRepository - 類似的問題已發佈在這裏 - http://stackoverflow.com/questions/36293960/custom-repository-base-class -querydslpredicateexecutor – Jeremy

回答

3

我結束了由有我的基地倉庫擴展和實現的QueryDslPredicateExecutor,而不是上級庫解決這一點。

// Custom repository interface 
@NoRepositoryBean 
public interface ExtendedMongoRepository<T, ID extends Serializable> extends MongoRepository<T, ID>, QueryDslPredicateExecutor<T>{ 

    public Page<T> query(Query query, Pageable pageable); 

} 


// Custom Repository Implementation 
public abstract class ExtendedMongoRepositoryImpl<T, ID extends Serializable> extends QueryDslMongoRepository<T, ID> 
     implements ExtendedMongoRepository<T, ID> { 

    private Class<T> clazz; 
    private MongoOperations mongoOperations; 
    @SuppressWarnings("unused") 
    private MongoEntityInformation<T, ID> metadata; 

    public ExtendedMongoRepositoryImpl(MongoEntityInformation<T, ID> metadata, MongoOperations mongoOperations) { 
     super(metadata, mongoOperations); 
     this.mongoOperations = mongoOperations; 
     this.clazz = metadata.getJavaType(); 
     this.metadata = metadata; 
    } 

    @Override 
    public Page<T> query(Query query, Pageable pageable) { 
     List<T> list = mongoOperations.find(query.with(pageable), clazz); 
     return new PageImpl<T>(list, pageable, list.size()); 
    } 
} 

// Entity Repository Interface 
public interface TreeRepository extends ExtendedMongoRepository<Tree, String> {} 
+0

公共類不抽象? – tg44

+0

這是在我的應用程序,我忘了更新我的解決方案。謝謝! – Jeremy

+0

http://stackoverflow.com/questions/38153365/springboot-couchbase-integration也許這個任何想法? – tg44

0

更改

extends SimpleJpaRepository

extends QueryDslJpaRepository

在我的基地JPA回購IMPL

做對我來說。

相關問題