问题
I'm having a Spring Data repository class like:
@RepositoryDefinition(domainClass = Book.class, idClass = Long.class)
public interface BookRepository {
List<Book> findAll();
List<Book> findByOrderByPublishDateDesc();
Book findOne(Long id);
Book save(Book book);
boolean exists(Long id);
void delete(Long id);
Iterable<Book> findAll(Predicate predicate, OrderSpecifier<?>... orders);
}
The standard crud methods do work, however the findAll (from JpaSpecificationExecutor) doesn't work.
Do @RepositoryDefinition repositories support using the querydsl (or jpa specification) predicate-aware methods?
回答1:
According the javadoc
Annotation to demarcate interfaces a repository proxy shall be created for. Annotating an interface with
RepositoryDefinitionwill cause the same behaviour as extendingRepository.
So it only supports the basic set available on Repository (at least that is what I deduce from the docs). If you want more you probably have to extend the specific interface next to adding the annotation.
@RepositoryDefinition(domainClass = Book.class, idClass = Long.class)
public interface BookRepository extends JpaSpecificationExecutor<Book> {}
来源:https://stackoverflow.com/questions/29026755/using-repositorydefinition-and-jpaspecificationexecutor-methods-doesnt-work