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()); }
Role role = (Role) it.next(); Map newRole = new HashMap(); newRole.put("username", user.getUsername()); newRole.put("roleName", role.getName());  List userRoles = getSqlMapClientTemplate().queryForList("getUserRoles", user.getUsername());  if (userRoles.isEmpty()) { getSqlMapClientTemplate().update("addUserRole", newRole); }
    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());                }                                }        }    }