spring - One-One ORM and insertion in DB -


i have one-one mapping of classes employee , department. have bean classes in domain. have front end jsp employee form. form has drop down box lists departments available.

now need insert operation of employee, using hibernate.

<form:form action="add" method="post" modelattribute="user">     <div>         <form:label path="emailaddress">email</form:label>         <form:input path="emailaddress" />     </div>     <div>         <form:label path="deptartment">department</form:label>         <form:select path="department">         <form:options items="${departmentlist}" />         </form:select>     </div> </form:form> 

controller method:

@requestmapping(value = "add", method = requestmethod.post)     public string getaddemployeesettingspage(@modelattribute("employee") employee employee,             bindingresult result) {          system.out.println(employee);         return "empsettings";     } 

now, employee object has no reference department. should fetch employee object in controller along associated department reference. hope clear. in advance.

inject dao controller, have controller fetch department associate employee dao, , persist employee.

ideally, you'd want wrap logic service method, service take employee, , persist appropriate department. also, wouldn't relation many-to-one, many employee's belong 1 department. otherwise, you'd have employee bob belongs department bob, employee sue belongs department sue, etc.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -