hibernate - map multiple model attributes to a ModelAndView in spring -
i have tried implement one-to-many association using spring , hibernate. cant implement 2 model attributes using single form. how map 2 model attributes in single form.
my controller code is,
@requestmapping(value = "/admin/test", method = requestmethod.get) public modelandview admintestpage(@modelattribute("employee") employee employee, @modelattribute("education")education education, bindingresult result, modelmap map, model model) { return new modelandview("test","command",new employee()); }
my jsp form is,
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@taglib uri="http://www.springframework.org/tags" prefix="spring" %> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>insert title here</title> </head> <body> <form:form method="post" action="saveemp"> <table > <tr> <td>employee name : </td> <td><form:input path="empname" /></td> </tr> <tr> <td>address :</td> <td><form:input path="empaddress" /></td> </tr> <tr> <td>salary :</td> <td><form:input path="salary" /></td> </tr> <tr> <td>salary :</td> <td><form:input path="qualification" /></td> </tr> <tr> <td>salary :</td> <td><form:input path="stream" /></td> </tr> <tr> <td>age :</td> <td><form:input path="empage" /> <input type="hidden" name="${_csrf.parametername}" value="${_csrf.token}"/></td> </tr> <tr> <td> </td> <td><input type="submit" value="save" /></td> </tr> </table> </form:form> </body> </html>
my employee.java entity code is,
@entity @table(name="employee") public class employee implements serializable{ private static final long serialversionuid = -723583058586873479l; @id @generatedvalue(strategy=generationtype.auto) @column private integer empid; @column private string empname; @column private string empaddress; @column private long salary; @column private integer empage; @transient private list<education> education; public integer getempid() { return empid; } public void setempid(integer empid) { this.empid = empid; } public string getempname() { return empname; } public void setempname(string empname) { this.empname = empname; } public string getempaddress() { return empaddress; } public void setempaddress(string empaddress) { this.empaddress = empaddress; } public long getsalary() { return salary; } public void setsalary(long salary) { this.salary = salary; } public integer getempage() { return empage; } public void setempage(integer empage) { this.empage = empage; } public list<education> geteducation() { return education; } public void seteducation(list<education> education) { this.education = education; } }
education.java entity is,
@entity @table(name="education") public class education{ @id @sequencegenerator(name = "seq_contacts", sequencename = "seq_contacts") @generatedvalue(strategy = generationtype.auto, generator = "seq_contacts") private int eduid; @column private string qualification; @column private string stream; @manytoone @joincolumn(name="empid") private employee employee; public education(){ } public education(int eduid, string qualification,string stream, employee employee ) { super(); this.eduid = eduid; this.qualification = qualification; this.stream=stream; this.employee = employee; } public int geteduid() { return eduid; } public void seteduid(int eduid) { this.eduid = eduid; } public string getqualification() { return qualification; } public void setqualification(string qualification) { this.qualification = qualification; } public string getstream() { return stream; } public void setstream(string stream) { this.stream = stream; } public employee getemployee() { return employee; } public void setemployee(employee employee) { this.employee = employee; }
error is,
org.springframework.beans.notreadablepropertyexception: invalid property 'qualification' of bean class [com.java.web.model.employee]: bean property 'qualification' not readable or has invalid getter method: return type of getter match parameter type of setter? org.springframework.beans.beanwrapperimpl.getpropertyvalue(beanwrapperimpl.java:708) org.springframework.beans.beanwrapperimpl.getpropertyvalue(beanwrapperimpl.java:699) org.springframework.validation.abstractpropertybindingresult.getactualfieldvalue(abstractpropertybindingresult.java:99) org.springframework.validation.abstractbindingresult.getfieldvalue(abstractbindingresult.java:218) org.springframework.web.servlet.support.bindstatus.<init>(bindstatus.java:120) org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getbindstatus(abstractdataboundformelementtag.java:179) org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getpropertypath(abstractdataboundformelementtag.java:199) org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getname(abstractdataboundformelementtag.java:165) org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.autogenerateid(abstractdataboundformelementtag.java:152) org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.resolveid(abstractdataboundformelementtag.java:143) org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.writedefaultattributes(abstractdataboundformelementtag.java:127) org.springframework.web.servlet.tags.form.abstracthtmlelementtag.writedefaultattributes(abstracthtmlelementtag.java:421) org.springframework.web.servlet.tags.form.inputtag.writetagcontent(inputtag.java:142) org.springframework.web.servlet.tags.form.abstractformtag.dostarttaginternal(abstractformtag.java:103) org.springframework.web.servlet.tags.requestcontextawaretag.dostarttag(requestcontextawaretag.java:80) org.apache.jsp.web_002dinf.pages.test_jsp._jspx_meth_form_005finput_005f4(test_jsp.java:328) org.apache.jsp.web_002dinf.pages.test_jsp._jspx_meth_form_005fform_005f0(test_jsp.java:169) org.apache.jsp.web_002dinf.pages.test_jsp._jspservice(test_jsp.java:80) org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) javax.servlet.http.httpservlet.service(httpservlet.java:727) org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432) org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:395) org.apache.jasper.servlet.jspservlet.service(jspservlet.java:339) javax.servlet.http.httpservlet.service(httpservlet.java:727) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) org.springframework.web.servlet.view.internalresourceview.rendermergedoutputmodel(internalresourceview.java:238) org.springframework.web.servlet.view.abstractview.render(abstractview.java:264) org.springframework.web.servlet.dispatcherservlet.render(dispatcherservlet.java:1208) org.springframework.web.servlet.dispatcherservlet.processdispatchresult(dispatcherservlet.java:992) org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:939) org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:856) org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:953) org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:844) javax.servlet.http.httpservlet.service(httpservlet.java:620) org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:829) javax.servlet.http.httpservlet.service(httpservlet.java:727) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) org.springframework.security.web.access.intercept.filtersecurityinterceptor.invoke(filtersecurityinterceptor.java:118) org.springframework.security.web.access.intercept.filtersecurityinterceptor.dofilter(filtersecurityinterceptor.java:84) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.access.exceptiontranslationfilter.dofilter(exceptiontranslationfilter.java:113) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.session.sessionmanagementfilter.dofilter(sessionmanagementfilter.java:103) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.authentication.anonymousauthenticationfilter.dofilter(anonymousauthenticationfilter.java:113) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.servletapi.securitycontextholderawarerequestfilter.dofilter(securitycontextholderawarerequestfilter.java:154) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.savedrequest.requestcacheawarefilter.dofilter(requestcacheawarefilter.java:45) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.authentication.www.basicauthenticationfilter.dofilter(basicauthenticationfilter.java:150) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.authentication.abstractauthenticationprocessingfilter.dofilter(abstractauthenticationprocessingfilter.java:199) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.authentication.logout.logoutfilter.dofilter(logoutfilter.java:110) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.csrf.csrffilter.dofilterinternal(csrffilter.java:85) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.context.request.async.webasyncmanagerintegrationfilter.dofilterinternal(webasyncmanagerintegrationfilter.java:50) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.session.concurrentsessionfilter.dofilter(concurrentsessionfilter.java:125) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.context.securitycontextpersistencefilter.dofilter(securitycontextpersistencefilter.java:87) org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) org.springframework.security.web.filterchainproxy.dofilterinternal(filterchainproxy.java:192) org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:160) org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:343) org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:260)
please 1 me solve this.
Comments
Post a Comment