Hibernate正在自动保存一个全新的实体(完整的调用堆栈)

| 我已经问过两次这个问题,但是我是Stackoverflow的新手,似乎我不知道此处格式化示例代码的规则。现在,我决定提供全部电话,希望我能解释这种情况,因为一切都太奇怪了,我找不到描述它的单词。首先,我将为您提供与问题有关的类的源。我的实际问题在页面末尾。大段代码只是为了以防万一,因为我不知道可能是我的问题的解释。 这是一个服务外观,可从我的flex应用程序获取调用。
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);
    }
}
对于我的问题而言重要的方法是findDuplicateEmails方法。 profileService在以下类中实现:
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 现在,经过这短暂的背景之后,这是我的问题: 我正在将spring的HibernateTemplate与Hibernate一起使用。我发现在findDuplicateEmails方法中,来自flex应用程序的一些全新实体会自动保存。这是非常奇怪的,在进行调试期间,我发现即使我在ProfileManager中更改了findDuplicateEmails方法,它也看起来像:
 @Override
 public List<Email> findDuplicateEmails(Long profileId, List<Email> emails) {   
     Email email = new Email();
     return null;
 }
实体电子邮件会自动保存。我还发现,如果实体的标识符不是\“ email \”,而是诸如\“ newEmail \”或\“ email1 \”之类的东西,则没有问题,并且如果出现以下情况,该实体将持久化并且只有当我使它持久化时。此问题仅在此类中存在,最后,此问题仅在电子邮件中出现。我的意思是,如果我有
Phone phone = new Phone();
,那么实体电话只会在我希望的时候保持不变。 flex应用程序首先检查从用户电子邮件输入的内容是否唯一,然后在某些用户交互之后,如果输入的数据有效,则调用方法“ 5”。     
已邀请:
        我将下载Hibernate源代码并开始调试,您将在Hibernate(发生)或代码中发现错误,因为这是一种奇怪的行为。 这是我一次得到的建议,并且是最快,最有教育意义的扎根方法。     

要回复问题请先登录注册