title: org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError
body: <p>I don't understand this error I'm getting, it has become very frustating... I'm trying to use DataTables to display the data from to tables with oneToMany relationship, the only way the data is displayed in the view is by setting to null the relationship, that way the error above disappears but then I don't know how to display the data as I need to. Thanks in advance.</p>
  
  <p>In user:</p>
  
  <pre><code>@JoinColumn(name = "id_rol", referencedColumnName = "id_rol", foreignKey = @ForeignKey(name = "fk_di")) 
  @ManyToOne(optional = false) 
  private Rol rol;
  </code></pre>
  
  <hr>
  
  <pre><code>@GetMapping("/users/pag")
  @ResponseBody
  public String usersPaginate(HttpServletRequest request, HttpServletResponse response) {
  
      DataTableRequest&lt;User&gt; dataTableInRQ = new DataTableRequest&lt;User&gt;(request);
      PaginationCriteria pagination = dataTableInRQ.getPaginationRequest();
  
      String baseQuery = "SELECT id_user, username, name, lastname, password, id_rol, (SELECT COUNT(1) FROM user) AS total_records FROM user ORDER BY lastname ASC";
      String paginatedQuery = AppUtil.buildPaginatedQuery(baseQuery, pagination);
  
      Query query = entityManager.createNativeQuery(paginatedQuery, User.class);
  
      @SuppressWarnings("unchecked")
      List&lt;User&gt; usersList = query.getResultList();
  
      /*
      for (int i = 0; i&lt;usersList.size(); i++){
          usersList.get(i).setRol(null);
      }*/
  
      DataTableResults&lt;User&gt; dataTableResult = new DataTableResults&lt;User&gt;();
      dataTableResult.setDraw(dataTableInRQ.getDraw());
      dataTableResult.setListOfDataObjects(usersList);
      if (!AppUtil.isObjectEmpty(usersList)) {
          dataTableResult.setRecordsTotal(usersList.get(0).getTotalRecords().toString());
          if (dataTableInRQ.getPaginationRequest().isFilterByEmpty()) {
              dataTableResult.setRecordsFiltered(usersList.get(0).getTotalRecords().toString());
          } else {
              dataTableResult.setRecordsFiltered(Integer.toString(usersList.size()));
          }
      }
  
      return new Gson().toJson(dataTableResult);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>$(document)
      .ready(
              function() {
                  var table = $('#paginatedTable')
                          .DataTable(
                                  {
                                      initComplete : function() {
                                          var input = $(
                                                  '.dataTables_filter input')
                                                  .unbind(), self = this
                                                  .api(), $searchButton = $(
                                                  '#search')
                                                  .click(
                                                          function() {
                                                              self
                                                                      .search(
                                                                              input
                                                                                      .val())
                                                                      .draw();
                                                          })
                                      },
                                      "processing" : true,
                                      "serverSide" : true,
                                      "pageLength" : 10,
                                      "lengthChange" : false,
                                      "columnDefs" : [
                                              {
                                                  targets : '_all',
                                                  orderable : false
                                              },
                                              {
                                                  targets : [ 0, 3, 4, 5, 6 ],
                                                  "className" : "text-center"
                                              },
                                              {
                                                  targets : [ 3, 4, 5, 6, 7 ],
                                                  searchable : false
                                              },
                                              {
                                                  targets : [ 6 ],
                                                  render : function(data,
                                                          type, row) {
                                                      return data == true ? 'Habilitado'
                                                              : 'Deshabilitado'
                                                  }
                                              },
                                              {
                                                  targets : [ 4 ],
                                                  render : function(data,
                                                          type, row) {
                                                      return moment(data)
                                                              .format(
                                                                      "DD/MM/YYYY");
                                                  }
                                              },
                                              {
                                                  targets : [ 7 ],
                                                  data : "idUser",
                                                  render : function(data,
                                                          type, row, meta) {
                                                      return '&lt;div class="btn-group"&gt;&lt;a href="/users/ed/'
                                                              + data
                                                              + '"&gt;&lt;img class="btnEdit" src="/images/edit.png"&gt;&lt;/a&gt;&lt;/div&gt;';
                                                  }
                                              } ],
                                      "ajax" : {
                                          "url" : "/users/pag",
                                          "data" : function(data) {
                                          }
                                      },
                                      "columns" : [ {
                                          "data" : "username"
                                      }, {
                                          "data" : "lastname"
                                      }, {
                                          "data" : "name"
                                      }, {
                                          "data" : "rol.tipoRol",
                                          render : function(data, type, row) {
                                              return data || '';
                                          }
                                      }]
                                  });
              });
  </code></pre>
  
  <hr>
  
  <pre><code>   org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:982) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) [spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) [tomcat-embed-core-8.5.16.jar:8.5.16]
  2018-01-18 00:00:11.508 ERROR 9160 --- [nio-8091-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.StackOverflowError] with root cause
  
  java.lang.StackOverflowError: null
  at java.util.Calendar.get(Calendar.java:1826) ~[na:1.8.0_144]
  at java.text.SimpleDateFormat.subFormat(SimpleDateFormat.java:1119) ~[na:1.8.0_144]
  at java.text.SimpleDateFormat.format(SimpleDateFormat.java:966) ~[na:1.8.0_144]
  at java.text.SimpleDateFormat.format(SimpleDateFormat.java:936) ~[na:1.8.0_144]
  at java.text.DateFormat.format(DateFormat.java:345) ~[na:1.8.0_144]
  </code></pre>