Java Spring Boot - JPA - Hibernate - H2 - Paging with Filtering and Sorting

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ส.ค. 2020
  • In this video we will learn how to implement paging, sorting and filtering for our entity using Criteria API. Our technological stack is Java Spring Boot, JPA, Hibernate and H2 database engine. We will deep dive into Criteria API so we will work with things like EntityManager, CriteriaBuilder and CriteriaQuery. We will learn how to create regular query to retrieve information about entity and also how to implement count query. Everything easly explained step by step.
    You can source code here: github.com/codeforgeyt/jpa-pa...
    Follow //CodefForgeYT on:
    FB: / codeforgeyt
    Twitter: / codeforgeyt
    GitHub: github.com/codeforgeyt
    Instagram: / codeforgeyt

ความคิดเห็น • 56

  • @regenschirm22
    @regenschirm22 2 ปีที่แล้ว

    thank you so much, you helped me understand this theme

    • @CodeForgeYT
      @CodeForgeYT  2 ปีที่แล้ว +1

      Glad I could help!

  • @charcequence
    @charcequence 2 ปีที่แล้ว +1

    I solve my problem for 4min, thanks to video!

  • @rohitverma8184
    @rohitverma8184 ปีที่แล้ว

    Thx bro love you videos

  • @joaquinolmedovillodres2518
    @joaquinolmedovillodres2518 2 ปีที่แล้ว

    Hello, thank you for the tutorial. I'm trying to add a Date to the predicate this way and it's not working, should be any difference?

  • @mohamedalivip3390
    @mohamedalivip3390 ปีที่แล้ว

    Thank you very much
    Can you explain if i want to make query with joined table using criteria builder

  • @sukanyamondal8892
    @sukanyamondal8892 3 ปีที่แล้ว +6

    great tutorial, can you make a video about joins and range (like date between?) your way of teaching is very easy to wrap our heads around

    • @CodeForgeYT
      @CodeForgeYT  3 ปีที่แล้ว

      Hey! Glad you like it. You meanr join and date between using Criteria API? Keep coding!

    • @sukanyamondal8892
      @sukanyamondal8892 3 ปีที่แล้ว +1

      @@CodeForgeYT yes exactly, it would be a nice addition to the next step to this.

    • @CodeForgeYT
      @CodeForgeYT  3 ปีที่แล้ว

      @@sukanyamondal8892 Thanks for idea!

  • @abdelmajidtaybi5949
    @abdelmajidtaybi5949 3 ปีที่แล้ว +1

    Thank you very much

  • @arsensargsyan774
    @arsensargsyan774 2 ปีที่แล้ว

    Thanks , how use like.root.get("enumName") enum type from string parameter?

  • @timmy8846
    @timmy8846 2 ปีที่แล้ว +1

    Thanks

  • @mohamednoser
    @mohamednoser 2 ปีที่แล้ว +1

    Thank You very much

  • @srinathselvam6512
    @srinathselvam6512 ปีที่แล้ว

    Hi, incase of custom count query based on multiple table joins.. how to get total count records for pagination?

  • @niladrisekharnath
    @niladrisekharnath 10 หลายเดือนก่อน

    Hey thanks for this great video can you please provide a link of the video where we can get the swagger ui and work with our endpoints Like how to set it up and use that ?

  • @kanismit5491
    @kanismit5491 3 ปีที่แล้ว +4

    Hi , nice tutorial but what about joins ? for example i need to filter by fields that in other table

    • @CodeForgeYT
      @CodeForgeYT  3 ปีที่แล้ว

      Hi! Thanks for feedback!
      I am not showing it because for people which are just getting started with Criteria API it is already hard enough, but yes it is possible to make joins.
      There is a special generic class called Join . Take a closer look on it. Keep coding!

    • @timmy8846
      @timmy8846 2 ปีที่แล้ว

      Exactly I really this rn, have you been able to get a solution?

    • @nikitayakovlev394
      @nikitayakovlev394 2 ปีที่แล้ว

      @@timmy8846 Hi, did you find a solution?

  • @falseys
    @falseys 2 ปีที่แล้ว

    Nice Tutorial, Thank you! One question, In real time how do we pass two different objects EmployeeSearchCriteria and Employee Page to get mapping method in the controller, For Example when testing it in post man

    • @tomsheldonworld
      @tomsheldonworld 2 ปีที่แล้ว

      you can pass as nested objects in json (use post or put method)

    • @TechOnScreen
      @TechOnScreen 2 ปีที่แล้ว

      can you tell how to make this postman call ? any sample please.

  • @Khantia
    @Khantia ปีที่แล้ว

    Why aren't you using @Autowired tho? In the project I'm working on, the "regular" repository is already using this annotation (within the service... and the service is also autowired in the controller) and now I don't know how to adjust your code in order to make them both work together.

    • @user-ps7op6gc2t
      @user-ps7op6gc2t ปีที่แล้ว +1

      Because he used constructor injection

  • @rosssihovsk5950
    @rosssihovsk5950 2 ปีที่แล้ว

    Hey, i saw in comments idea about filering information in range(date between). is it worth waiting for the video or have you changed your mind about making it?

    • @CodeForgeYT
      @CodeForgeYT  2 ปีที่แล้ว

      Hey. Thanks for comment. I think it will be quicker to look for different source of information for this topic.

    • @rosssihovsk5950
      @rosssihovsk5950 2 ปีที่แล้ว +1

      @@CodeForgeYT ok, thanks for the answer

  • @pratikghotekar8664
    @pratikghotekar8664 2 ปีที่แล้ว +1

    Hello , How we can use operators like ,! in as query params in the URL. How can i extract and use in the criteria builder

    • @CodeForgeYT
      @CodeForgeYT  2 ปีที่แล้ว +1

      Well you can use whatever you want. For example lets say we have ?sortOrder=asc. We cane use this in for example if statement to check if order direction should be ascending or descending

    • @pratikghotekar8664
      @pratikghotekar8664 2 ปีที่แล้ว

      @@CodeForgeYT thanks for reply.
      ?firstName=abc&Age>20
      I can retrieve firstName directly but how can i retrive Age?

    • @CodeForgeYT
      @CodeForgeYT  2 ปีที่แล้ว

      @@pratikghotekar8664 You can do something like: ?age.gt=20 or ?age[gt]=20 then you have to parse such key to know how to check the value. There is a lot of different approaches.

  • @BlendSkMix
    @BlendSkMix ปีที่แล้ว

    If field has null values , how to make it return value zero??
    Using criteria builder.
    In sql i know we use IFNULL(NULL,0)

    • @user-ku8qb1rn1g
      @user-ku8qb1rn1g ปีที่แล้ว

      variable.equals("null")? variable = 0 : { };

  • @sunnyisonvacation
    @sunnyisonvacation 3 ปีที่แล้ว +1

    nice . But im unable to find github code for this tutorial ?

    • @CodeForgeYT
      @CodeForgeYT  3 ปีที่แล้ว +2

      Hey! Thanks for feedback! I have uploaded source code to github. You can find link in video description. Happy coding! :D

  • @averagedev7768
    @averagedev7768 2 ปีที่แล้ว +1

    Could we just use Pagable interface from spring boot itseflf

    • @CodeForgeYT
      @CodeForgeYT  2 ปีที่แล้ว +1

      Hi, of course you can. I have an video about this topic on my channel. You can check it out. Using Criteria API you have more control over SQL queries so you can optimize them to increase performance in complex scenarios. Kee coding

  • @Runnable19
    @Runnable19 9 หลายเดือนก่อน

    Thanks for the work but I think this video needs to be updated because of this problem "Error Message: Already registered a copy: SqmBasicValuedSimplePath". I'm using java 21.

  • @artemryvkin6885
    @artemryvkin6885 2 ปีที่แล้ว

    nice video, but it will be good to get more explanation about used objects and methods... Because most of the video - just retelling or spelling the code you write

    • @CodeForgeYT
      @CodeForgeYT  2 ปีที่แล้ว

      You can read about each method by hitting ctrl + q

  • @BabaykaMoscow
    @BabaykaMoscow 2 ปีที่แล้ว +1

    Is it possible to sort by multiple fields?

    • @CodeForgeYT
      @CodeForgeYT  2 ปีที่แล้ว +1

      If you will pass multiple arguments to orderBy method, I think it will order by multiple fields

    • @BabaykaMoscow
      @BabaykaMoscow 2 ปีที่แล้ว +1

      @@CodeForgeYT Will check that out. Thank you!

  • @WaqarAhmad-ik9dt
    @WaqarAhmad-ik9dt ปีที่แล้ว

    Thank you so much, How we can filter with nested objects
    product {
    title;
    Detail detail;
    }
    Detail {
    description;
    }

    • @user-ku8qb1rn1g
      @user-ku8qb1rn1g ปีที่แล้ว

      Did you find the answer? I also encountered the same!

  • @arhim7650
    @arhim7650 2 ปีที่แล้ว +1

    Nice, but i don't like solution, when you need to go over two time in DB, scond it's when you get pageCount.

    • @CodeForgeYT
      @CodeForgeYT  2 ปีที่แล้ว

      Hey! Thanks for feedback! Keep coding!

  • @karlrussellmenil9460
    @karlrussellmenil9460 3 ปีที่แล้ว +1

    Topic: Full stack javascript - Data Pagination and Filtering
    Good day,
    If I may humbly ask a little help, any hints, comments and suggestions are very much welcome, thank you in advance for all your help, please see question below, how do I code this?:
    /*
    Create the `showPage` function
    This function will create and insert/append the elements needed to display a "page" of nine students
    */
    /*
    Create the `addPagination` function
    This function will create and insert/append the elements needed for the pagination buttons
    */
    // Call functions

    • @CodeForgeYT
      @CodeForgeYT  3 ปีที่แล้ว +1

      Hey!
      Regarding your topic I understand it this way. I assume it should be MVC app, so you want to create student model, student view and student controller. Your controller will return student view together with the list of the students. Also this list should be filterable and pageable.
      But it is only my assumption, It would be the best to ask author

    • @CodeForgeYT
      @CodeForgeYT  3 ปีที่แล้ว +1

      Please don't post code or links in the comments.
      Comments section is used to discuss video/channel related stuff and share thoughts about it.
      If you are looking for advice regarding your code you can share it for example on stackoverflow it is way better place than comments sections.
      Keep Coding!

    • @karlrussellmenil9460
      @karlrussellmenil9460 3 ปีที่แล้ว

      @@CodeForgeYT deleted as per your request :)

  • @jespinala
    @jespinala 7 หลายเดือนก่อน

    Thanks for this great video!
    I have followed it carefully and I am getting this error when this is executed: rbillingCriteriaQuery.from(Rbilling.class)
    org.springframework.dao.InvalidDataAccessApiUsageException: Not an entity: class itk.dbaccounting.rbilling.Rbilling; nested exception is java.lang.IllegalArgumentException: Not an entity: class itk.dbaccounting.rbilling.Rbilling Could you suggest anything about it?