Project

General

Profile

Revision 7450d44b

ID7450d44bf31c73a41b69d836d1b87f0305784ad7
Parent b317a252
Child fe3180d3

Added by Andreas Kohlbecker over 3 years ago

fix #7702 always clearing session in finally clause

View differences:

src/main/java/eu/etaxonomy/cdm/service/CdmStore.java
9 9
package eu.etaxonomy.cdm.service;
10 10

  
11 11
import org.apache.log4j.Logger;
12
import org.hibernate.HibernateException;
13 12
import org.hibernate.Session;
14 13
import org.hibernate.engine.spi.SessionImplementor;
15 14
import org.springframework.transaction.TransactionStatus;
......
167 166
            session.flush();
168 167
            commitTransaction();
169 168
            return new EntityChangeEvent(mergedBean, changeEventType, view);
170
        } catch (HibernateException | IllegalStateException e){
169
        } finally {
171 170
            session.clear(); // #7559
172
            throw e;
173 171
        }
174 172
    }
175 173

  
......
195 193
                handleDeleteresultInError(result, session);
196 194
                txStatus = null;
197 195
            }
198
        } catch (HibernateException e){
196
        } finally {
199 197
            session.clear(); // #7559
200
            throw e;
201 198
        }
202 199
        return null;
203 200
    }
......
217 214
            messageBody.append("<h3>").append("Exceptions:").append("</h3>").append("<ul>");
218 215
            result.getExceptions().forEach(e -> messageBody.append("<li>").append(e.getMessage()).append("</li>"));
219 216
            messageBody.append("</ul>");
217
            /*
218
             * not needed since covered by clear() in finally clause
220 219
            if(result.getExceptions().stream().anyMatch(e -> HibernateException.class.isAssignableFrom(e.getClass()))){
221 220
                session.clear(); // #7559
222 221
            }
222
            */
223 223
        }
224 224
        if (!result.getRelatedObjects().isEmpty()) {
225 225
            messageBody.append("<h3>").append("Related objects exist:").append("</h3>").append("<ul>");
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
474 474
    @EventBusListenerMethod
475 475
    public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
476 476
        if(event.getPopup() instanceof TaxonNamePopupEditor){
477
            TransactionStatus txStatus = getRepo().startTransaction();
478
            if(event.getReason().equals(Reason.SAVE)){
479
                if(newTaxonNameForRegistration != null){
480
                    UUID taxonNameUuid = newTaxonNameForRegistration.getUuid();
481
                    getRepo().getSession().refresh(newTaxonNameForRegistration);
482
                    Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid);
483
                    // reload workingset into current session
484
                    loadWorkingSet(workingset.getCitationUuid());
485
                    workingset.add(reg);
486
                }
487
                refreshView(true);
488
            } else if(event.getReason().equals(Reason.CANCEL)){
489
                if(newTaxonNameForRegistration != null){
490
                    // clean up
491
                    getTaxonNameStore().deleteBean(newTaxonNameForRegistration, (AbstractView) getView());
477
            try {
478
                TransactionStatus txStatus = getRepo().startTransaction();
479
                if(event.getReason().equals(Reason.SAVE)){
480
                    if(newTaxonNameForRegistration != null){
481
                        UUID taxonNameUuid = newTaxonNameForRegistration.getUuid();
482
                        getRepo().getSession().refresh(newTaxonNameForRegistration);
483
                        Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid);
484
                        // reload workingset into current session
485
                        loadWorkingSet(workingset.getCitationUuid());
486
                        workingset.add(reg);
487
                    }
488
                    refreshView(true);
489
                } else if(event.getReason().equals(Reason.CANCEL)){
490
                    if(newTaxonNameForRegistration != null){
491
                        // clean up
492
                        getTaxonNameStore().deleteBean(newTaxonNameForRegistration, (AbstractView) getView());
493
                    }
492 494
                }
495
                getRepo().commitTransaction(txStatus);
496
            } finally {
497
                getRepo().getSession().clear(); // #7702
493 498
            }
494
            getRepo().commitTransaction(txStatus);
495 499
            newTaxonNameForRegistration = null;
496 500
        }
497 501
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)