commit 7450d44bf31c73a41b69d836d1b87f0305784ad7
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Wed Aug 29 18:50:19 2018 +0200

    fix #7702 always clearing session in finally clause

diff --git a/src/main/java/eu/etaxonomy/cdm/service/CdmStore.java b/src/main/java/eu/etaxonomy/cdm/service/CdmStore.java
index c366c073..4c87d49c 100644
--- a/src/main/java/eu/etaxonomy/cdm/service/CdmStore.java
+++ b/src/main/java/eu/etaxonomy/cdm/service/CdmStore.java
@@ -9,7 +9,6 @@
 package eu.etaxonomy.cdm.service;
 
 import org.apache.log4j.Logger;
-import org.hibernate.HibernateException;
 import org.hibernate.Session;
 import org.hibernate.engine.spi.SessionImplementor;
 import org.springframework.transaction.TransactionStatus;
@@ -167,9 +166,8 @@ public class CdmStore<T extends CdmBase, S extends IService<T>> {
             session.flush();
             commitTransaction();
             return new EntityChangeEvent(mergedBean, changeEventType, view);
-        } catch (HibernateException | IllegalStateException e){
+        } finally {
             session.clear(); // #7559
-            throw e;
         }
     }
 
@@ -195,9 +193,8 @@ public class CdmStore<T extends CdmBase, S extends IService<T>> {
                 handleDeleteresultInError(result, session);
                 txStatus = null;
             }
-        } catch (HibernateException e){
+        } finally {
             session.clear(); // #7559
-            throw e;
         }
         return null;
     }
@@ -217,9 +214,12 @@ public class CdmStore<T extends CdmBase, S extends IService<T>> {
             messageBody.append("<h3>").append("Exceptions:").append("</h3>").append("<ul>");
             result.getExceptions().forEach(e -> messageBody.append("<li>").append(e.getMessage()).append("</li>"));
             messageBody.append("</ul>");
+            /*
+             * not needed since covered by clear() in finally clause
             if(result.getExceptions().stream().anyMatch(e -> HibernateException.class.isAssignableFrom(e.getClass()))){
                 session.clear(); // #7559
             }
+            */
         }
         if (!result.getRelatedObjects().isEmpty()) {
             messageBody.append("<h3>").append("Related objects exist:").append("</h3>").append("<ul>");
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
index d31e6068..dc43f0e3 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
@@ -474,24 +474,28 @@ public class RegistrationWorkingsetPresenter extends AbstractPresenter<Registrat
     @EventBusListenerMethod
     public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
         if(event.getPopup() instanceof TaxonNamePopupEditor){
-            TransactionStatus txStatus = getRepo().startTransaction();
-            if(event.getReason().equals(Reason.SAVE)){
-                if(newTaxonNameForRegistration != null){
-                    UUID taxonNameUuid = newTaxonNameForRegistration.getUuid();
-                    getRepo().getSession().refresh(newTaxonNameForRegistration);
-                    Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid);
-                    // reload workingset into current session
-                    loadWorkingSet(workingset.getCitationUuid());
-                    workingset.add(reg);
-                }
-                refreshView(true);
-            } else if(event.getReason().equals(Reason.CANCEL)){
-                if(newTaxonNameForRegistration != null){
-                    // clean up
-                    getTaxonNameStore().deleteBean(newTaxonNameForRegistration, (AbstractView) getView());
+            try {
+                TransactionStatus txStatus = getRepo().startTransaction();
+                if(event.getReason().equals(Reason.SAVE)){
+                    if(newTaxonNameForRegistration != null){
+                        UUID taxonNameUuid = newTaxonNameForRegistration.getUuid();
+                        getRepo().getSession().refresh(newTaxonNameForRegistration);
+                        Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid);
+                        // reload workingset into current session
+                        loadWorkingSet(workingset.getCitationUuid());
+                        workingset.add(reg);
+                    }
+                    refreshView(true);
+                } else if(event.getReason().equals(Reason.CANCEL)){
+                    if(newTaxonNameForRegistration != null){
+                        // clean up
+                        getTaxonNameStore().deleteBean(newTaxonNameForRegistration, (AbstractView) getView());
+                    }
                 }
+                getRepo().commitTransaction(txStatus);
+            } finally {
+                getRepo().getSession().clear(); // #7702
             }
-            getRepo().commitTransaction(txStatus);
             newTaxonNameForRegistration = null;
         }
     }
