“No property exists found for type”… When using the QueryDslPredicateExecutor with MongoDB and Spring-Data

前端 未结 2 1792
南笙
南笙 2021-01-18 17:33

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 -



        
相关标签:
2条回答
  • 2021-01-18 18:17

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

    // 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 讨论(0)
  • 2021-01-18 18:28

    Changing

    extends SimpleJpaRepository

    for

    extends QueryDslJpaRepository

    in my base JPA repo impl made it for me.

    0 讨论(0)
提交回复
热议问题