title: nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type
body: <p>I am getting the following validation error when I try to submit my form. The dropdown box populated with values from Document.java gives this error: </p>
  
  <pre><code>Failed to convert property value of type java.lang.String to required type 
  testapp.domain.Document for property document_number; nested exception is 
  java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] 
  to required type [testapp.domain.Document] for property document_number: no matching 
  editors or conversion strategy found
  </code></pre>
  
  <p>Is there something wrong with my mapping? </p>
  
  <p>Document.java mapping</p>
  
  <pre><code>    @OneToMany(mappedBy="document_number", cascade = CascadeType.ALL)
  private Set&lt;DocumentRevision&gt; documentRevisions;
  
  public void setDocumentRevisions(Set&lt;DocumentRevision&gt; documentRevisions){
      this.documentRevisions = documentRevisions;
  }
  </code></pre>
  
  <p>DocumentRevision.java mapping</p>
  
  <pre><code>    @ManyToOne(cascade = CascadeType.ALL)
  @JoinColumn(name="DOCUMENT_NUMBER")
  private Document document_number; 
  
  public void setDocument_number(Document document_number){
      this.document_number = document_number;
  }
  
  public Document getDocument_number(){
      return document_number;
  }
  </code></pre>
  
  <p>The relationship between the two tables is that several <em>DocumentRevisions</em> can have the same <em>DocumentNumber</em> but a single <em>DocumentRevision</em> can only have one <em>DocumentNumber</em></p>
  
  <p>Thank you for your help</p>
  
  <p>/D</p>
  
  <p><strong>Edit</strong>  </p>
  
  <p>I am using spring 3.0 and hibernate 3. <a href="https://stackoverflow.com/questions/10499641/how-to-populate-dropdown-box-in-spring-mvc">Here</a> is a recent thread by me which includes the controller and jsp page. </p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>Here is the DAO Implementation method that is supposed to save the document_number into DocumentRevision</p>
  
  <pre><code>    public void saveDocumentRevision(DocumentRevision documentRevision) {
      this.sessionFactory.getCurrentSession().save(documentRevision); 
  }
  </code></pre>
  
  <p><strong>Edit 3</strong></p>
  
  <p>I believe this is the part of the code where document_number should be recorded. Do I have to use "documentNumberList" somewhere in the .POST method? How would I do that in that case?</p>
  
  <p>part of controller: </p>
  
  <pre><code>@RequestMapping(value="/add", method=RequestMethod.GET)
  public String getDocumentRevision(Model model) {
  DocumentRevision documentRevision = new DocumentRevision();
  model.addAttribute("documentRevisionAttribute", documentRevision);
  model.addAttribute("documentNumberList", documentService.retrieveAllDocumentNumbers());
  
  return "new-documnent-revision";
  }
  
  
  @RequestMapping(value="/add", method=RequestMethod.POST)
  public String postDocumentRevision(@ModelAttribute("documentRevisionAttribute") @Valid DocumentRevision documentRevision, BindingResult result) {
  
  if(result.hasErrors()){
      return "new-document-revision";
  }
  
  documentRevisionService.createDocumentRevision(documentRevision);
  return "redirect:/testapp/document-revision/list";  
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I have added the following to my controller:</p>
  
  <pre><code>    /**
   * Property editor to map Documents from documents IDs.
   */
  
   class DocumentPropertyEditor extends PropertyEditorSupport {
  
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
          Document value =  documentService.retrieveDocumentNumber(text);
          setValue(value);
      }
  
      @Override
      public String getAsText() {
          Document d = (Document) getValue();
          return d != null ? String.valueOf(d.getDocumentNumber()) : "";
      }
  
  }
  
  
  @InitBinder
  public void initBinder(WebDataBinder binder) {
      binder.registerCustomEditor(Document.class, new DocumentPropertyEditor());
  }
  </code></pre>
  
  <p>I am now getting a NullPointerException:</p>
  
  <pre><code>java.lang.NullPointerException
  testapp.controller.DocumentRevisionController$DocumentPropertyEditor.getAsText(DocumentRevisionController.java:59)
  </code></pre>
  
  <p>Why isn't the getter in th PropertyEditor getting a value? </p>
  
  <p><strong>Edit 4</strong></p>
  
  <p>the retrieveDocumentNumber(text) method:</p>
  
  <pre><code>    public Document retrieveDocumentNumber(String text){
      return (Document) this.sessionFactory.getCurrentSession().get(Document.class, text);
  }
  </code></pre>