title: How to fix "Failed to convert from type java.lang.String to type @javax.persistence.Id" when show a recursive model in a JSP view
body: <p>I created a model with a recursive relation, but when I tray to show it in a <code>form:select</code> in a JSP view, it returns an error about datatype conversions, how can I show recursive model in a JSP view?</p>
  
  <p>I'm using Java 1.8 and spring-core 4.1.</p>
  
  <p>When I show a database row, that the recursive field is <code>null</code>, it works, but when I try to show a row with the recursive field filled with a valid value, it doesn't works and generate the error.</p>
  
  <p>this is the model field from the class Category</p>
  
  <pre><code>@OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
  @JoinColumn(nullable=true)
  private Category subCategory;
  </code></pre>
  
  <p>my controller send to the JSP view, a Category object named "category"</p>
  
  <pre><code>modelAndView.addObject("category", category);
  </code></pre>
  
  <p>in the view I'm showing the object by a form:select component</p>
  
  <pre><code>&lt;form:select path="subCategory.id" 
               id="category_subCategory"
               multiple="false"
               cssClass="form-control"&gt;
    &lt;form:option value="null"&gt;-&lt;/form:option&gt;
    &lt;form:options items="${categories}"
                  itemValue="id"
                  itemLabel="name"/&gt;
  &lt;/form:select&gt;
  </code></pre>
  
  <p>Instead of displaying the  component, it's breaking and generating the error below:</p>
  
  <blockquote>
    <p>Jun 26, 2019 4:03:09 PM org.apache.catalina.core.ApplicationDispatcher invoke SEVERE: Servlet.service() for servlet [jsp] threw exception
    java.lang.NumberFormatException: For input string: "null" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)...</p>
    
    <p>Jun 26, 2019 4:03:09 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/ecommerce] threw exception [javax.servlet.ServletException: javax.servlet.jsp.JspException: org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.persistence.Id @javax.persistence.GeneratedValue java.lang.Integer for value 'null';
    nested exception is java.lang.NumberFormatException: For input string: "null"] with root cause java.lang.NumberFormatException: For input string: "null"...</p>
  </blockquote>