When I try to submit my form, I get the following validation error. In the drop-down list filled with values ββfrom Document.java, the following error appears:
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
Is there something wrong with my image?
Display Document.java
@OneToMany(mappedBy="document_number", cascade = CascadeType.ALL) private Set<DocumentRevision> documentRevisions; public void setDocumentRevisions(Set<DocumentRevision> documentRevisions){ this.documentRevisions = documentRevisions; }
Display DocumentRevision.java
@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; }
The relationship between the two tables is that multiple DocumentRevisions can have the same DocumentNumber, but one DocumentRevision can have only one DocumentNumber
thanks for the help
/ D
Edit
I am using spring 3.0 and hibernate 3. Here is a recent thread that includes a controller page and jsp.
Edit 2
Here is a DAO implementation method that should save document_number in DocumentRevision
public void saveDocumentRevision(DocumentRevision documentRevision) { this.sessionFactory.getCurrentSession().save(documentRevision); }
Edit 3
I believe this is the part of the code in which document_number is written. Should I use "documentNumberList" somewhere in the .POST method? How can I do this in this case?
controller part:
@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"; }
Update
I added the following to the controller:
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()); }
Now I get a NullPointerException:
java.lang.NullPointerException testapp.controller.DocumentRevisionController$DocumentPropertyEditor.getAsText(DocumentRevisionController.java:59)
Why is there no value in the receiver PropertyEditor?
Change 4
retrieveDocumentNumber method (text):
public Document retrieveDocumentNumber(String text){ return (Document) this.sessionFactory.getCurrentSession().get(Document.class, text); }