specification-projection

Support specification with projection for Spring Data JPA

License

License

GroupId

GroupId

th.co.geniustree
ArtifactId

ArtifactId

specification-with-projections
Last Version

Last Version

1.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

specification-projection
Support specification with projection for Spring Data JPA
Project URL

Project URL

https://github.com/pramoth/specification-with-projection
Project Organization

Project Organization

Pivotal Software, Inc.
Source Code Management

Source Code Management

https://github.com/pramoth/specification-with-projection

Download specification-with-projections

How to add to project

<!-- https://jarcasting.com/artifacts/th.co.geniustree/specification-with-projections/ -->
<dependency>
    <groupId>th.co.geniustree</groupId>
    <artifactId>specification-with-projections</artifactId>
    <version>1.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/th.co.geniustree/specification-with-projections/
implementation 'th.co.geniustree:specification-with-projections:1.0.4'
// https://jarcasting.com/artifacts/th.co.geniustree/specification-with-projections/
implementation ("th.co.geniustree:specification-with-projections:1.0.4")
'th.co.geniustree:specification-with-projections:jar:1.0.4'
<dependency org="th.co.geniustree" name="specification-with-projections" rev="1.0.4">
  <artifact name="specification-with-projections" type="jar" />
</dependency>
@Grapes(
@Grab(group='th.co.geniustree', module='specification-with-projections', version='1.0.4')
)
libraryDependencies += "th.co.geniustree" % "specification-with-projections" % "1.0.4"
[th.co.geniustree/specification-with-projections "1.0.4"]

Dependencies

provided (4)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-data-jpa jar 1.5.7.RELEASE
org.springframework.boot : spring-boot-starter-web jar 1.5.7.RELEASE
org.springframework.data : spring-data-jpa jar
org.hibernate : hibernate-jpamodelgen jar 5.0.12.Final

test (2)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 1.5.7.RELEASE
com.h2database : h2 jar 1.4.196

Project Modules

There are no modules declared in this project.

specification-with-projection

Support Projections with JpaSpecificationExecutor.findAll(Specification,Pageable) for Spring Data JPA

version 2.x.x for Spring Data JPA 2.x (Spring Boot 2.x)

version 1.x.x Spring Data JPA 1.x

How to use

  • add dependency to pom
<!-- for Spring Data 2.x -->
<dependency>
    <groupId>th.co.geniustree.springdata.jpa</groupId>
    <artifactId>specification-with-projections</artifactId>
    <version>2.0.1</version>
</dependency>
<!-- for Spring Data 1.x -->
<dependency>
    <groupId>th.co.geniustree.springdata.jpa</groupId>
    <artifactId>specification-with-projections</artifactId>
    <version>1.0.6</version>
</dependency>
  • add annotation @EnableJpaRepositories(repositoryBaseClass = JpaSpecificationExecutorWithProjectionImpl.class) on Application class (Spring Boot)
  • create your repository and extends JpaSpecificationExecutorWithProjection
public interface DocumentRepository extends JpaRepository<Document,Integer>,JpaSpecificationExecutorWithProjection<Document,Integer> {
    /**
    * projection interface
    **/
    public static interface DocumentWithoutParent{
        Long getId();
        String getDescription();
        String getDocumentType();
        String getDocumentCategory();
        List<DocumentWithoutParent> getChild();
    }
}
  • use it

        @Test
      public void specificationWithProjection() {
          Specifications<Document> where = Specifications.where(DocumentSpecs.idEq(1L));
          Page<DocumentRepository.DocumentWithoutParent> all = documentRepository.findAll(where, DocumentRepository.DocumentWithoutParent.class, new PageRequest(0,10));
          Assertions.assertThat(all).isNotEmpty();
      }
JpaEntityGraph jpaEntityGraph = new JpaEntityGraph(
    "birth.sistRecvTm",
    EntityGraph.EntityGraphType.FETCH,
    new String[]{"sistRecvTm","birth","transfer","merger"}
  );
  BirthWithoutChild birth = birthRepository.findAll(createSpecBirth(searchData, type.toUpperCase()), BirthWithoutChild.class,jpaEntityGraph,pageable);

Versions

Version
1.0.4