Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!transit3.readnews.com!postnews.google.com!l36g2000vbp.googlegroups.com!not-for-mail From: stunaz Newsgroups: comp.lang.java.programmer Subject: Problems with WebDataBinder and Set.Class Date: Wed, 20 Apr 2011 19:13:58 -0700 (PDT) Organization: http://groups.google.com Lines: 109 Message-ID: NNTP-Posting-Host: 76.69.234.238 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1303352039 20129 127.0.0.1 (21 Apr 2011 02:13:59 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 21 Apr 2011 02:13:59 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l36g2000vbp.googlegroups.com; posting-host=76.69.234.238; posting-account=-FSIfAoAAADL7WRV0exwpmcOiKwrynQm User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.205 Safari/534.16,gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3172 Hello everyone, i am having trouble with binding my data from a form : I have two class @Entity @Table(name = "ROLES") public class Role implements GenericDomain { private Long id; private String code; private String name; private Set privileges = new HashSet(0); public Role() {} /* getter and setter*/ @ManyToMany(cascade=CascadeType.ALL) @JoinTable(name = "ROLES_PRIVILEGES" , joinColumns = { @JoinColumn(name = "ROLE_ID") } , inverseJoinColumns = { @JoinColumn(name = "PRIVILEGE_ID") } ) public Set getPrivileges() { return this.privileges; } public void setPrivileges(Set privileges) { this.privileges = privileges; } /* overide of hascode, equals*/ } And @Entity @Table(name = "PRIVILEGES") public class Privilege implements GenericDomain { private Long id; private String code; private Set roles = new HashSet(0); public Privilege() {} /* getter and setter*/ @ManyToMany(cascade=CascadeType.REFRESH, mappedBy="privileges") public Set getRoles() { return this.roles; } public void setRoles(Set roles) { this.roles = roles; } @Override public String toString(){ return this.getCode() + this.getComment(); } /*overide equals and hascode*/ and in my controller i have : @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(Set.class, "privileges", new CustomCollectionEditor(Set.class) { @Override protected Object convertElement(Object element) { return (element == null)? null:privilegeService.getOne(Integer.parseInt((String)element)); } }); } @RequestMapping(value = "edit", method = RequestMethod.POST) public String saveOldRole( @ModelAttribute("role") Role role , BindingResult result , ModelMap model ) { validator.validate(role, result); if (result.hasErrors()){ logger.error(result.getAllErrors()); model.addAllAttributes(result.getModel()); return "/admin/role/edit"; } logger.info(role.getPrivileges()); Iterator p = role.getPrivileges().iterator(); while(p.hasNext()){ logger.info(p.next().getClass()); } roleService.saveOrUpdate(role); model.addAttribute("roles", roleService.getAll()); sessionStatus.setComplete(); return "redirect:/admin/role/list.do"; } and my debug is role.RoleController:93 - [[MANAGE_USERS], [MANAGE_ROLES]] role.RoleController:96 - class java.util.LinkedHashSet role.RoleController:96 - class java.util.LinkedHashSet 22:29:44,915 ERROR tomcat-http--7 property.BasicPropertyAccessor:194 - IllegalArgumentException in class: com.stunaz.domain.Privilege, getter method of property: id I dont understand why at 96, the class type is java.util.LinkedHashSet, i thought it should be Privileges. I dont understand why my role.getPrivileges() is a Set of Set, it should be a Set of Privilege. Of course at saveOrUpdate am getting an error.