Jeremy Jeremy - 1 year ago 366
Java Question

"No property exists found for type"... When using the QueryDslPredicateExecutor with MongoDB and Spring-Data

I'm trying to use the QueryDslPredicateExecutor with MongoDB and Spring-Data, but it seems to be choking on the "exists()" property.

I'm using -


Stack Trace

Caused by: No property exists found for type Tree!
at<init>( ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at<init>( ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at$OrPart.<init>( ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at$Predicate.buildTree( ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at$Predicate.<init>( ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at<init>( ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at<init>( ~[spring-data-mongodb-1.9.0.RELEASE.jar:na]
at$MongoQueryLookupStrategy.resolveQuery( ~[spring-data-mongodb-1.9.0.RELEASE.jar:na]
at$QueryExecutorMethodInterceptor.<init>( ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at ~[spring-data-mongodb-1.9.0.RELEASE.jar:na]
at ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
... 30 common frames omitted

The exception is being thrown from this class

// 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(); = propertyName;

The property (method) is coming from the QueryDslPredicateExecutor class that my Repository extends.

public abstract boolean

Here is the repository -

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

Answer Source

I ended up solving this by having my base repository extend and implement the QueryDslPredicateExecutor, rather than the higher level repository.

// Custom repository interface
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;
    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;

    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> {}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download