Hibernate automatically saves a completely new object (full call stack)

I already asked this question twice, but I'm new to stackoverflow, and it seems like I don't know the formatting rules for the sample code here. Now I decided to give a complete call stack, and I hope that I can explain the situation, because everything is so strange, and I can not find words to describe it. First I will give you a source of classes that have something to do with the problem. My actual question is at the end of the page. Most of the code just in case, because I do not know what could be the explanation of my problem. Here is a service facade that calls calls from my flex application.

public class ServiceFacade implements IAuthenticationService, IProfileService, ICampaignService {
    @Autowired
    private IAuthenticationService authenticationService;

    @Autowired
    private IProfileService profileService;

    @Autowired
    private ICampaignService campaignService;

    public void login(User user) throws AuthenticationException{
        authenticationService.login(user);
    }

    @Override
    public void logout() throws AuthenticationException {
        authenticationService.logout();
    }

    @Override
    public void sendForgottenPassword(String email) {
        authenticationService.sendForgottenPassword(email);
    }

    @Override
    public Profile getProfile(Long userId) {
        return profileService.getProfile(userId);
    }

    @Override
    public Profile updateProfile(Profile profile) {
        return profileService.updateProfile(profile);
    }

    @Override
    public Collection<String> getSocialConnectionsTypes(Long userId) {
        return profileService.getSocialConnectionsTypes(userId);
    }

    @Override
    public List<Email> findDuplicateEmails(Long profileId, List<Email> emails) {
        return profileService.findDuplicateEmails(profileId, emails);
    }

    @Override
    public Campaign getCampaign(Long campaignId) {
        return campaignService.getCampaign(campaignId);
    }

    @Override
    public Campaign updateCampaign(Campaign campaign) {
        return campaignService.updateCampaign(campaign);
    }

    @Override
    public void removeCampaign(Long campaignId) {
        campaignService.removeCampaign(campaignId);
    }

    @Override
    public void setPools(Long campaignId, Collection<Pool> pools) {
        campaignService.setPools(campaignId, pools);
    }

    @Override
    public void addPool(Long campaignId, Pool pool) {
        campaignService.addPool(campaignId, pool);
    }

    @Override
    public void removePool(Long campaignId, Pool pool) {
        campaignService.removePool(campaignId, pool);
    }

    @Override
    public List<Campaign> getCampaigns() {
        return campaignService.getCampaigns();
    }

    @Override
    public void updatePool(Long campaignId, Pool pool) {
        campaignService.updatePool(campaignId, pool);
    }
}

A method important to my question is the findDuplicateEmails method .

ProfileService is implemented in the following class:

public class ProfileService implements IProfileService {
    @Autowired
    private IProfileManager profileManager;

    @Override
    public Profile getProfile(Long userId) {
        return profileManager.getProfile(userId);
    }

    @Override
    public Profile updateProfile(Profile profile){
        profileManager.updateProfile(profile);
        return profile;
    }

    @Override
    public Collection<String> getSocialConnectionsTypes(Long userId) {
        return profileManager.getSocialConnectionsTypes(userId);
    }

    @Override
    public List<Email> findDuplicateEmails(Long profileId, List<Email> emails) {
        return profileManager.findDuplicateEmails(profileId, emails);
    }
}

: findDuplicateEmails

profileManager :

public class ProfileManager implements IProfileManager {
    @Autowired
    private IProfileDao profileDao;

    @Autowired
    private ISectionManager autoCompleteManager;

    @Autowired
    private IUserSecurityService userSecurityService;
    @Transactional
    public Profile getProfile(Long userId) {
        return profileDao.getProfileByUser(userId);
    }

    @Transactional
    public void updateProfile(final Profile profile) {

        List<Major> notApprovedMajors = extractNotApprovedMajors(profile);
        List<Degree> notApprovedDegrees = extractNotApprovedDegrees(profile);
        List<School> notApprovedSchools = extractNotApprovedSchools(profile);
        List<Language> notApprovedLanguages = extractNotApprovedLanguages(profile);
        List<Position> notApprovedPositions = extractNotApprovedPositions(profile);
        List<Company> notApprovedCompanies = extractNotApprovedCompanies(profile);
        List<Country> notApprovedCountries = extractNotApprovedCountries(profile);
        List<City> notApprovedCities = extractNotApprovedCities(profile);
        List<Certificate> notApprovedCertificates = extractNotApprovedCertificates(profile);

        autoCompleteManager.updateAll(notApprovedMajors);
        autoCompleteManager.updateAll(notApprovedDegrees);
        autoCompleteManager.updateAll(notApprovedSchools);
        autoCompleteManager.updateAll(notApprovedLanguages);
        autoCompleteManager.updateAll(notApprovedPositions);
        autoCompleteManager.updateAll(notApprovedCompanies);
        autoCompleteManager.updateAll(notApprovedCountries);
        autoCompleteManager.updateAll(notApprovedCities);
        autoCompleteManager.updateAll(notApprovedCertificates);

        profileDao.updateProfile(profile);
    }

    @Override
    public List<Email> findDuplicateEmails(Long profileId, List<Email> emails) {

        Profile persistedProfile = profileDao.findById(profileId);

        if (persistedProfile.getContact() == null)
        {
            persistedProfile.setContact(new Contact());
        }

        List<Email> resultEmails = new ArrayList<Email>();

        for (int i = 0; i < emails.size(); i++) {

            if ((!userSecurityService.guaranteeUniquePrincipal(emails.get(i)) &&
                    !isPersistedInThePersistentCollection(emails.get(i), persistedProfile.getContact().getEmails())) ||
                    isDuplicateInTheCurrentCollection(emails.get(i), emails, i + 1)) {
                resultEmails.add(emails.get(i));
            }
    }

        return resultEmails;
    }

    private boolean isDuplicateInTheCurrentCollection(Email emailToCheck, List<Email> emails, int index)
    {

        for (int i = index ; i < emails.size(); i ++) {
            if (emails.get(i).getEmailAddress().equals(emailToCheck.getEmailAddress())) {
                return true;
            }
        }

        return false;
    }

    private boolean isPersistedInThePersistentCollection(Email emailToCheck, Collection<Email> emails)
    {
        if (emails == null) {
            return false;
        }
        for (Email persistedEmail : emails) {
            if (persistedEmail.getEmailAddress().equalsIgnoreCase(emailToCheck.getEmailAddress())) {
                return true;
            }
        }

        return false;
    }
}

findDuplicateEmails

, , :

Hibernate spring HibernateTemplate. , findDuplicateEmails , flex, . , debbugging , findDuplicateEmails ProfileManager, :

 @Override
 public List<Email> findDuplicateEmails(Long profileId, List<Email> emails) {   
     Email email = new Email();
     return null;
 }

. , " ", - , "newEmail" "email1", - , , , . , , , . , Phone phone = new Phone();, , .

flex , , updateProfile(), .

+5
1

Hibernate , Hibernate (), , . , , , .

0

All Articles