From 0c4f8e751f41bdad03e237dd6b4588144158a4a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 22 Aug 2016 12:56:42 +0200 Subject: [PATCH] Please cherry-pick: - fetch entity first with getReference(), then make it detached (maybe right?), then merge it - added missing javadoc reference (URL) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- lib/nblibraries.properties | 2 ++ .../database/BaseAddressbookDatabaseBean.java | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/nblibraries.properties b/lib/nblibraries.properties index 09266ab..f508429 100644 --- a/lib/nblibraries.properties +++ b/lib/nblibraries.properties @@ -9,4 +9,6 @@ libs.javaee-api-7.0.prop-maven-dependencies=javax:javaee-api:7.0:jar libs.jpa20-persistence.classpath=\ ${base}/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar libs.jpa20-persistence.displayName=Persistence (JPA 2.1) +libs.jpa20-persistence.javadoc=\ + https://docs.oracle.com/javaee/7/api/ libs.jpa20-persistence.prop-maven-dependencies=org.eclipse.persistence:javax.persistence:2.1.0:jar diff --git a/src/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java b/src/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java index 3c951a8..3963d9b 100644 --- a/src/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java +++ b/src/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java @@ -29,8 +29,11 @@ import org.mxchange.jcoreee.database.BaseDatabaseBean; import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper; import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.phonenumbers.mobile.MobileNumber; import org.mxchange.jphone.utils.PhoneUtils; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; @@ -76,8 +79,11 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { // Is contact cellphone set? if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Copy cellphone number - contact.setContactMobileNumber(this.getDetached(contact.getContactMobileNumber(), contact.getContactMobileNumber())); + // Fetch it from entity manager + DialableMobileNumber fetchedNumber = this.getEntityManager().getReference(MobileNumber.class, contact.getContactMobileNumber().getPhoneId()); + + // Copy mobile number + contact.setContactMobileNumber(this.getDetached(contact.getContactMobileNumber(), fetchedNumber)); } // Debug message @@ -85,8 +91,11 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { // Is the land-line number set? if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { + // Fetch it from entity manager + DialableLandLineNumber fetchedNumber = this.getEntityManager().getReference(LandLineNumber.class, contact.getContactLandLineNumber().getPhoneId()); + // Copy land-line number - contact.setContactLandLineNumber(this.getDetached(contact.getContactLandLineNumber(), contact.getContactLandLineNumber())); + contact.setContactLandLineNumber(this.getDetached(contact.getContactLandLineNumber(), fetchedNumber)); } // Debug message @@ -94,8 +103,11 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { // Is the fax number set? if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { + // Fetch it from entity manager + DialableFaxNumber fetchedNumber = this.getEntityManager().getReference(FaxNumber.class, contact.getContactFaxNumber().getPhoneId()); + // Copy fax number - contact.setContactFaxNumber(this.getDetached(contact.getContactFaxNumber(), contact.getContactFaxNumber())); + contact.setContactFaxNumber(this.getDetached(contact.getContactFaxNumber(), fetchedNumber)); } // Trace message @@ -172,6 +184,9 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { if (null == mobileNumber) { // Throw NPE throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (null == fetchedNumber) { + // Throw NPE again + throw new NullPointerException("fetchedNumber is null"); //NOI18N } else if (fetchedNumber.getPhoneId() == null) { // ..and again throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N @@ -186,15 +201,13 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { // Debug message this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N - // Default is null - DialableMobileNumber detachedNumber = null; + // Default is fetched number + DialableMobileNumber detachedNumber = fetchedNumber; // Is there a difference? if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) { // Merge this entry detachedNumber = this.getEntityManager().merge(foundNumber); - - // Copy all } // Trace message -- 2.39.5