hibernate - Spring form controller: unable to save relations in form controller -



hibernate - Spring form controller: unable to save relations in form controller -

i have 3 tables user, role , userrolerelationships (many-to-many bring together table). in service have no problem editing user , saving relating roles, i'm not able in controller.

expected behaviour in service:

hibernate: update dbo.users set username=?, password=?, email=?, workphone=?, privatephone=?, fullname=? userid=? hibernate: update dbo.userroles set role=? roleid=? hibernate: update dbo.userroles set role=? roleid=?

but behaviour in controller are:

hibernate: update dbo.users set username=?, password=?, email=?, workphone=?, privatephone=?, fullname=? userid=? hibernate: delete userrolerelationships userid=?

my controller looks like:

@requestmapping(value = "/usermanagement/edit/{userid}") public modelandview initupdateform(@pathvariable string userid, modelmap model) { model.addattribute("user", iwusermanagementservice.getuser(integer.valueof(userid))); homecoming new modelandview(viewname, model); } @requestmapping(value = "/usermanagement/edit/{userid}", method = requestmethod.post) public modelandview processupdatesubmit(@modelattribute("user") iwuser iwuser, bindingresult result, sessionstatus status){ iwusermanagementservice.saveorupdate(iwuser); status.setcomplete(); homecoming new modelandview("redirect:/usermanagement", new modelmap("user", iwuser)); }

part of web.xml:

<filter> <filter-name>hibernatefilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.opensessioninviewfilter</filter-class> <init-param> <param-name>singlesession</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>flushmode</param-name> <param-value>auto</param-value> </init-param> <init-param> <param-name>sessionfactorybeanname</param-name> <param-value>sessionfactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>hibernatefilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

for me looks user model in processupdatesubmit() not homecoming roles, posted items. how can create homecoming roles well?

thanks :)

from comments, seams roles "disappears in process function".

it seams have problem form or way request handled.

i sentiment have 2 choices, depending on want do:

if not want alter users roles (in form) utilize user info tansfer object instead of role in processupdatesubmit. need load user , update info dto.

if want alter user roles (in form) need find bug:

check form submit roles check converters (role id role) work correct check spring can access collection of roles in user object. if looks ok, set break point user.setrole() method , go backward in phone call stack.

forms hibernate spring controller

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -