私はすでにこの質問を2回行っていますが、stackoverflowを初めて使用するため、ここでサンプルコードをフォーマットするためのルールがわからないようです。今、私は呼び出しの完全なスタックを提供することにしました。すべてが非常に奇妙で、それを説明する言葉が見つからないため、状況を説明できることを願っています。まず、問題に関係するクラスのソースを紹介します。私の実際の質問はページの最後にあります。大きなコードは念のためです。問題の説明が何であるかわからないためです。これが私のフレックスアプリケーションからの呼び出しを受け取るサービスファサードです。
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アプリケーションは、最初にユーザーの電子メールから入力されたものが一意であることを確認し、次にユーザーとの対話の後にupdateProfile()
、入力されたデータが有効かどうかをメソッドに呼び出します。