UserRole userRole = null; List preventDups = new ArrayList();
    private void addUserRoles(final User user) {        if (user.getRoles() != null) {            UserRole userRole = null;            List preventDups = new ArrayList();            for (Iterator it = user.getRoles().iterator(); it.hasNext();) {                userRole = (UserRole) it.next();                if (!preventDups.contains(userRole.getRoleName())) {                    Long pk = (Long) getSqlMapClientTemplate().queryForObject("getRoleId", null);                        if (pk == null) {                        pk = new Long(0);                    }                        userRole.setId(new Long(pk.longValue() + 1));                        userRole.setUserId(user.getId());                    userRole.setUsername(user.getUsername());                    getSqlMapClientTemplate().update("addUserRole", userRole);                    preventDups.add(userRole.getRoleName());                }                                }        }    }