Quoute form igniterealtime
"I am removing account it is not really removing rosters from that account. Later, when I will add account with same name it has already rosters in his roster list (same as before deleting account)."
This is the change I am making. To iterate the roster of the user and delete all roster items before deleting the actual user and thereby ensuring DB referential integrity.
public void deleteUser(String username) throws UserNotFoundException, SharedGroupException
{
Roster r = rosterManager.getRoster(username);
Collection<RosterItem> rosterItems = r.getRosterItems();
for (RosterItem rosterItem: rosterItems)
{
r.deleteRosterItem(rosterItem.getJid(), true);
}
User user = getUser(username);
userManager.deleteUser(user);
}
This works better
public void deleteUser(String username) throws UserNotFoundException, SharedGroupException
{
User user = getUser(username);
userManager.deleteUser(user);
rosterManager.deleteRoster(server.createJID(username, null));
}