spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
3.01k stars 1.42k forks source link

Add support for searching by Specification and Sort [DATAJPA-48] #484

Closed spring-projects-issues closed 11 years ago

spring-projects-issues commented 13 years ago

Stevo Slavić opened DATAJPA-48 and commented

JpaSpecificationExecutor public API has support for various combination of Specification, Sort, and Pageable. One is missing tho, findAll(Specification<T>, Sort). private TypedQuery<T> getQuery(Specification<T> spec, Sort sort) in JpaSpecificationExecutor already has everything to support exposing such API.

Attached patch [^DATAJPA-Adds-support-for-finding-by-spec-and-sort.patch] adds List<T> findAll(Specification<T> spec, Sort sort); to JpaSpecificationExecutor interface, appropriate implementation in SimpleJpaRepository and a test case.

Patch also configures project pom to add generated test source directory as maven test source directory using build-helper-maven-plugin. With this and m2eclipse configured to run "process-test-classes" goal on project import or when updating eclipse project configuration, project tests could compile


Affects: 1.0 M2

Reference URL: http://forum.springframework.org/showthread.php?p=356230

Attachments:

Referenced from: commits https://github.com/spring-projects/spring-data-jpa/commit/c4a71140c95a5d27dea9ffcc94ff97af14f96a32

spring-projects-issues commented 13 years ago

Stevo Slavić commented

Wish SimpleJpaRepository is more designed for extension. To add workaround until this ticket is resolved, had to duplicate/shadow fields and multiple methods. If only getEntityManager and getQuery methods were protected and not private

spring-projects-issues commented 13 years ago

Dustin Woods commented

I too would like to see the getQuery method be 'protected' instead of 'private' to apply query hints when using specifications. Should this be a separate issue?

spring-projects-issues commented 13 years ago

Oliver Drotbohm commented

I've added the method. What are you exactly meaning with the generated test source directory?

spring-projects-issues commented 13 years ago

Stevo Slavić commented

Some test sources are generated (using com.mysema.maven:maven-apt-plugin). Only default test source directory is src/test/java. For directory with generated test sources to be compiled and added to test scope classpath, build helper plugin is typically used. Without that ordinary test sources which reference generated test source do not compile.

Btw, some javadoc in SimpleJpaRepository has to be updated to reflect changes when JpaSpecificationExecutor was factored out of JpaRepository. I would have done that but formatting surely wouldn't be correct. SpringSource eclipse formatter used to exist

spring-projects-issues commented 13 years ago

Oliver Drotbohm commented

Hi Stevo, have you had a chance to check whether this works for you? The Maven build should just work fine anyway as the APT plugin transparently adds the configured target folder as source folder as well. It builds fine for me on the command line and also does in Eclipse (at least after having done Maven > Update Project configuration in m2eclipse).

spring-projects-issues commented 13 years ago

Stevo Slavić commented

It works for me too, updating project configuration does the trick. By default m2eclipse doesn't run any goals on Maven project import