GithubHelp home page GithubHelp logo

bernardomoraisbh / specification-with-projection-gradle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pramoth/specification-with-projection

0.0 0.0 0.0 156 KB

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

License: MIT License

Java 90.86% PLSQL 9.14%

specification-with-projection-gradle's Introduction

Build fork to work with GRADLE. Run it ignoring the tests, since meta model generator is not properly configured:

gradlew clean build -Dorg.gradle.java.home=C:\R2DA\java\jdk-11.0.10 -x test

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);

specification-with-projection-gradle's People

Contributors

dmonti avatar fleadram avatar mikhail88 avatar pramoth avatar thesivis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.