title: How to execute and parse query select to json inside an object returned by hibernate?
body: <p>This is a tricky one but I'll try to explain myself as better as I can.</p>
  
  <p>I have this method inside a controller class:</p>
  
  <pre><code>@CrossOrigin
  @RequestMapping(value = "/dashboard", params = {"user"}, method = RequestMethod.GET,  produces = "application/json")
  public ResponseEntity&lt;Map&lt;String, User&gt;&gt; getUser(@RequestParam(value = "user") String ldapId) {
  
      User user =  userService.findUserByLdapId(ldapId);
  
      if(user == null)
          return new ResponseEntity&lt;&gt;(HttpStatus.NO_CONTENT);
  
  
      Map&lt;String, User&gt; result = new HashMap&lt;String,User&gt;();
      result.put(User.class.getAnnotation(JsonRootName.class).value(), user);
  
  
      return new ResponseEntity&lt;&gt;(result, HttpStatus.OK);
  
  };
  </code></pre>
  
  <p>That one returns a json like this:</p>
  
  <pre><code>{
      "user": {
          "userId": 1,
          "fullName": "Carolina Ponce",
          "ldapId": "f8cygqn",
          "email": "carolina@blabla.com",
          "uType": "Administrador",
          "deleteFlag": "",
          "typeAccess": "",
          "roles": [
              {
                  "roleId": 2,
                  "roleName": "Account",
                  "sections": []
              },
              {
                  "roleId": 1,
                  "roleName": "Admin",
                  "sections": [
                      {
                          "sectionId": 1,
                          "sectionName": "Dashboard",
                          "components": [
                              {
                                  "componentId": 1,
                                  "componentName": "Rubros",
                                  "componentQuery": "SELECT Vertical_Id AS ID, Vertical_Desc AS NAME FROM D_DW_COMERCIAL.BAS_Vertical ORDER BY Vertical_Desc"
                              }
                          ]
                      }
                  ]
              }
          ]
      }
  }
  </code></pre>
  
  <p>As you can see I used hibernate and <code>@OneToMany</code> annotation to achieve this. A user has a list of roles, a role has a list of sections and so on.</p>
  
  <p>At the end I have a query stored in a table as you can see in <code>componentQuery</code>. The purpose of that query is to bring to the frontend something that will be rendered as a list, but that query will be different for each component, that's why I can't use hibernate to get the data of the select.</p>
  
  <p>I think that I need a way to, once I have the user returned by the userService, get that <code>componentQuery</code> execute it and put the result of that execution in the same json to be able to render that data then.</p>
  
  <p>This is the way I found to achieve this, but I listen to other alternatives too.</p>
  
  <p>Thanks.</p>