Entity inside Entity Class in builder



    Kishan Kumar


    When you have a entity which have entity as column inside then below code snippet shows how you add match clause of equal . As you know you in this case we cannot match the data using entity's variable directly . because data of variable that we are trying to match is present inside Entity class B and B entity class is present in our A Entity class .

    And A is out root class to which we are adding our below predicates .

    Suppose we need to match userID in db using entity class A, but variable related to data column is not in entity class A, but that variable is present inside the entity Class B. that is further present inside root Entity class A as a variable .

    private static Specification<EntityClass> isUserEqual(String userID) {
      return (root, cq, cb) -> cb.equal(root.get("B").get("userID"), userID);
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.