From: Roland Häder Date: Tue, 23 Aug 2016 15:50:42 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9686bd9011e30d6c3c4e48787beaf6d992eb04fd;p=jjobs-mailer-ejb.git Please cherry-pick: - if you don't want to have redundant entries (=objects aka. entities) in database of referenced entities, first you need to merge it as it is detached - then you have a managed instance which you can set in the referencing entity back - if you don't do this, the entity manager will "think" it is a new instance and persists + relinks it - maybe some implementations don't do this, but the JPA standard (generic) seems to want to have this way - do never implement for only one JPA implementation! Do always follow the generic JPA way --- diff --git a/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java index fa71e34..1e11f92 100644 --- a/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java @@ -97,8 +97,11 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData // Find contact Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); + // Merge phone number + DialableFaxNumber managedNumber = this.getEntityManager().merge(faxNumber); + // Set fax number in contact - managedContact.setContactFaxNumber(faxNumber); + managedContact.setContactFaxNumber(managedNumber); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N @@ -154,8 +157,11 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData // Find contact Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - // Set landline number in contact - managedContact.setContactLandLineNumber(landLineNumber); + // Merge phone number + DialableLandLineNumber managedNumber = this.getEntityManager().merge(landLineNumber); + + // Set fax number in contact + managedContact.setContactLandLineNumber(managedNumber); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N @@ -205,8 +211,11 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData // Find contact Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - // Set landline number in contact - managedContact.setContactMobileNumber(mobileNumber); + // Merge phone number + DialableMobileNumber managedNumber = this.getEntityManager().merge(mobileNumber); + + // Set fax number in contact + managedContact.setContactMobileNumber(managedNumber); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N