Example usage for org.hibernate Session merge

List of usage examples for org.hibernate Session merge

Introduction

In this page you can find the example usage for org.hibernate Session merge.

Prototype

Object merge(Object object);

Source Link

Document

Copy the state of the given object onto the persistent object with the same identifier.

Usage

From source file:de.fhdo.gui.admin.modules.collaboration.SysParamDetails.java

License:Apache License

public void onOkClicked() {
    // speichern mit Hibernate

    try {//ww w.j  a  v a2 s . c o  m
        if (logger.isDebugEnabled())
            logger.debug("Daten speichern");

        //sysParam.setDomainValueByModifyLevel(selectedModifyLevel);
        //attachment.getAttachment().setTechnicalTypeCd(selectedTechnicalType.getDomainCode());

        Session hb_session = HibernateUtil.getSessionFactory().openSession();
        hb_session.getTransaction().begin();
        try {

            if (newEntry) {
                hb_session.save(sysParam);
            } else {
                if (logger.isDebugEnabled())
                    logger.debug("Daten aktualisieren");

                hb_session.merge(sysParam);
            }

            if (iUpdateListener != null) {
                iUpdateListener.update(sysParam, !newEntry);
            }

            hb_session.getTransaction().commit();
        } catch (Exception e) {
            hb_session.getTransaction().rollback();
            logger.error("Fehler in onOkClicked() bei hibernate: " + e.getMessage());
            e.printStackTrace();
        } finally {
            hb_session.close();
        }

        this.setVisible(false);
        this.detach();
    } catch (Exception e) {
        // Fehlermeldung ausgeben
        //logger.error("Fehler in onOkClicked(): " + e.getMessage());
        LoggingOutput.outputException(e, this);
        if (hb_sessionS != null)
            hb_sessionS.close();
    }
    if (hb_sessionS != null)
        hb_sessionS.close();
    //Executions.getCurrent().setAttribute("contactPerson_controller", null);
}

From source file:de.fhdo.gui.admin.modules.collaboration.WorkflowDetails.java

License:Apache License

public void onOkClicked() {
    Session hb_session = HibernateUtil.getSessionFactory().openSession();

    try {/*from   w  w  w. j a v  a2  s.  c om*/
        if (cbAction.getSelectedItem() != null) {
            statusrel.setAction((Action) cbAction.getSelectedItem().getValue());
            logger.debug("Action: " + statusrel.getAction().getAction());
        }

        if (cbStatusFrom.getSelectedItem() != null) {
            statusrel.setStatusByStatusIdFrom((Status) cbStatusFrom.getSelectedItem().getValue());
            logger.debug("Status From: " + statusrel.getStatusByStatusIdFrom().getStatus());
        }

        if (cbStatusTo.getSelectedItem() != null) {
            statusrel.setStatusByStatusIdTo((Status) cbStatusTo.getSelectedItem().getValue());
            logger.debug("Status From: " + statusrel.getStatusByStatusIdTo().getStatus());
        }

        if (statusrel.getAction() == null || statusrel.getStatusByStatusIdFrom() == null
                || statusrel.getStatusByStatusIdTo() == null) {
            Messagebox.show("Bitte fllen Sie alle Pflichtfelder aus.");
            hb_session.close();
            return;
        }

        org.hibernate.Transaction tx = hb_session.beginTransaction();

        if (newEntry) {
            // Neuen Eintrag speichern

            hb_session.save(statusrel);

        } else {
            // Eintrag bearbeiten

            hb_session.merge(statusrel);
        }

        /*if (updateListInterface != null)
        {
          logger.debug("Lade neu mit ID: " + statusrel.getId());
                  
          statusrel = (Statusrel) hb_session.get(Statusrel.class, statusrel.getId());
                  
                
                  
          UpdateWorkflowType uType = new UpdateWorkflowType();
          uType.setHb_session(hb_session);
          uType.setO(statusrel);
                  
          updateListInterface.update(uType, !newEntry);
        }*/

        tx.commit();

    } catch (Exception ex) {
        LoggingOutput.outputException(ex, this);
    } finally {
        logger.debug("SESSION SCHLIESSEN!");
        hb_session.close();
    }

    // Fenster schlieen und Liste aktualisieren
    this.setVisible(false);
    this.detach();

    if (updateListInterface != null)
        updateListInterface.update(null, !newEntry);

    /*String mailResponse = "";
            
     // speichern mit Hibernate
     try
     {
     if (logger.isDebugEnabled())
     logger.debug("Daten speichern");
            
     Session hb_session = HibernateUtil.getSessionFactory().openSession();
     hb_session.getTransaction().begin();
            
     try
     {
     if (newEntry)
     {
     // Pflichtfelder prfen
     if(user.getUsername() == null || user.getUsername().length() == 0 || 
     user.getEmail() == null || user.getEmail().length() == 0 || user.getEmail().contains("@") == false ||
     cbUserRole.getSelectedItem() == null || user.getOrganisation().getOrganisation() == null || user.getOrganisation().getOrganisation().equals(""))
     {
     Messagebox.show("Sie mssen einen Benutzernamen, eine gltige Email-Adresse, Benutzerrolle und Organisation angeben.");
     hb_session.close();
     return;
     }
                  
     // prfen, ob Benutzer bereits existiert
     String hql = "from Collaborationuser where username=:user";
     Query q = hb_session.createQuery(hql);
     q.setParameter("user", user.getUsername());
     List userList = q.list();
     if(userList != null && userList.size() > 0)
     {
     Messagebox.show("Benutzers existiert bereits. Bitte whlen Sie einen anderen Benutzernamen.");
     hb_session.close();
     return;
     }
                  
     if (logger.isDebugEnabled())
     logger.debug("Neuer Eintrag, fuege hinzu!");
            
     // Passwort und Salt generieren
     String neuesPW = Password.generateRandomPassword(8);
     String salt = Password.generateRandomSalt();
     user.setPassword(Password.getSaltedPassword(neuesPW, salt, user.getUsername()));
     user.setSalt(salt);
     user.setActivated(false);
     user.setActivationMd5(MD5.getMD5(Password.generateRandomPassword(6)));     
                  
     Role r = (Role)hb_session.get(Role.class, CollabUserRoleHelper.getCollabUserRoleIdByName(cbUserRole.getSelectedItem().getLabel()));
     user.getRoles().clear();
     user.getRoles().add(r);
     // Benutzer speichern
     hb_session.save(user);
     user.getOrganisation().getCollaborationusers().clear();
     user.getOrganisation().getCollaborationusers().add(user);
                  
     hb_session.save(user.getOrganisation());
                  
     // Benachrichtigung senden
     mailResponse = Mail.sendMailCollaborationNewUser(user.getUsername(), neuesPW,
     user.getEmail(), user.getActivationMd5());
                  
     if (mailResponse.length() == 0)
     {
     hb_session.getTransaction().commit();
     Messagebox.show("Benutzer wurde erfolgreich angelegt und Aktivierungs-Email verschickt.");
     }
     else
     {
     Messagebox.show("Fehler beim Anlegen eines Benutzers: " + mailResponse);
     hb_session.getTransaction().rollback();
     }
                  
     neuesPW = "                       ";
     }
     else
     {
     Role r = (Role)hb_session.get(Role.class, CollabUserRoleHelper.getCollabUserRoleIdByName(cbUserRole.getSelectedItem().getLabel()));
     user.getRoles().clear();
     user.getRoles().add(r);
     hb_session.merge(user);
     hb_session.getTransaction().commit();
     }
                
     }
     catch (Exception e)
     {
     hb_session.getTransaction().rollback();
     logger.error("Fehler in DomainDetails.java (onOkClicked()): " + e.getMessage());
     }
            
     hb_session.close();
            
     this.setVisible(false);
     this.detach();
            
     if (updateListInterface != null)
     updateListInterface.update(user, !newEntry);
            
     }
     catch (Exception e)
     {
     // Fehlermeldung ausgeben
     logger.error("Fehler in BenutzerDetails.java: " + e.getMessage());
     hb_sessionS.close();
     }
     hb_sessionS.close();*/
}

From source file:de.fhdo.gui.admin.modules.terminology.domains.DomainDetails.java

License:Apache License

public void onOkClicked() {
    // speichern mit Hibernate
    try {//from   w w  w.  java  2 s .  c  o  m
        if (logger.isDebugEnabled())
            logger.debug("Daten speichern");

        if (getSelectedSortType() != null)
            domain.setDisplayOrder(getSelectedSortType().getDomainValueId());

        Session hb_session = HibernateUtil.getSessionFactory().openSession();
        hb_session.getTransaction().begin();

        try {
            if (newEntry) {
                if (logger.isDebugEnabled())
                    logger.debug("Neuer Eintrag, fuege der Domain hinzu!");

                //Domain d = (Domain) hb_session.get(Domain.class, domainId);
                //d.setDomain(domain);

                hb_session.save(domain);
            } else {
                hb_session.merge(domain);
            }
        } catch (Exception e) {
            logger.error("Fehler in DomainDetails.java (onOkClicked()): " + e.getMessage());
        }

        hb_session.getTransaction().commit();
        hb_session.close();

        //hb_session.close();

        this.setVisible(false);
        this.detach();

        if (getUpdateListInterface() != null)
            getUpdateListInterface().update(getDomain(), !newEntry);

    } catch (Exception e) {
        // Fehlermeldung ausgeben
        logger.error("Fehler in DomainDetails.java: " + e.getMessage());
        e.printStackTrace();
        if (hb_sessionS != null)
            hb_sessionS.close();
    }
    if (hb_sessionS != null)
        hb_sessionS.close();
}

From source file:de.fhdo.gui.admin.modules.terminology.domains.DomainValueDetails.java

License:Apache License

public void onOkClicked() {
    // speichern mit Hibernate
    try {/*from w  w w.ja v  a 2s .  c om*/
        if (domainValue.getDomainCode() == null || domainValue.getDomainCode().length() == 0) {
            Messagebox.show("Geben Sie bitte einen Code an.");
            return;
        }
        if (domainValue.getDomainDisplay() == null || domainValue.getDomainDisplay().length() == 0) {
            Messagebox.show("Geben Sie bitte einen Anzeige-Text an.");
            return;
        }

        if (logger.isDebugEnabled())
            logger.debug("Daten speichern");

        Session hb_session = HibernateUtil.getSessionFactory().openSession();
        hb_session.getTransaction().begin();

        try {

            if (newEntry) {
                if (logger.isDebugEnabled())
                    logger.debug("Neuer Eintrag, fuege der Domain hinzu!");

                Domain domain = (Domain) hb_session.get(Domain.class, domainId);
                domainValue.setDomain(domain);

                hb_session.save(domainValue);
            } else {
                hb_session.merge(domainValue);
            }

        } catch (Exception e) {
            logger.error("Fehler in DomainValueDetails.java in onOkClicked(): " + e.getMessage());
            e.printStackTrace();
        }

        hb_session.getTransaction().commit();
        hb_session.close();

        // Verbindungen speichern
        Textbox tb = (Textbox) getFellow("ueberID");
        String ueberIDs = tb.getValue();

        if (ueberIDs.length() > 0) {
            String[] ids = ueberIDs.split(";");
            for (int i = 0; i < ids.length; ++i) {
                long id = 0;
                if (ids[i].length() > 0) {
                    id = Long.parseLong(ids[i]);
                    DomainHelper.getInstance().saveUpperDomainID(domainValue.getDomainValueId(), id);
                }
            }
        }

        //hb_session.close();

        this.setVisible(false);
        this.detach();

        if (updateListInterface != null)
            updateListInterface.update(domainValue, !newEntry);

    } catch (Exception e) {
        // Fehlermeldung ausgeben
        logger.error("Fehler in DomainValueDetails.java: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:de.fhdo.gui.admin.modules.terminology.metadata.MetadatenDetails.java

License:Apache License

public void onOkClicked() {
    // speichern mit Hibernate
    try {//from  w ww  .  j a v a 2s  .co m
        boolean error = false;
        if (logger.isDebugEnabled())
            logger.debug("Daten speichern");

        Session hb_session = HibernateUtil.getSessionFactory().openSession();
        hb_session.getTransaction().begin();

        try {
            if (metadataParameter.getParamName() == null || metadataParameter.getParamName().equals("")) {
                Messagebox.show("Es muss ein Wert angegeben werden!", "Warning", Messagebox.OK,
                        Messagebox.EXCLAMATION);
                return;
            }

            // prfen, ob Wert bereits existiert
            if (newEntry) {
                String hql = "";
                org.hibernate.Query q = null;

                if (codeSystemId > 0) {
                    hql = "from MetadataParameter where codeSystemId=:cs_id and paramName=:name";
                    q = hb_session.createQuery(hql);
                    q.setParameter("cs_id", codeSystemId);
                } else if (valueSetId > 0) {
                    hql = "from MetadataParameter where valueSetId=:vs_id and paramName=:name";
                    q = hb_session.createQuery(hql);
                    q.setParameter("vs_id", valueSetId);
                }

                if (q != null) {
                    q.setParameter("name", metadataParameter.getParamName());
                    List list = q.list();
                    if (list != null && list.size() > 0) {
                        Messagebox.show(
                                "Dieser Parameter ist fr das ausgewhlte Code System bereits vorhanden!",
                                "Achtung", Messagebox.OK, Messagebox.EXCLAMATION);
                        return;
                    }
                }
            }

            metadataParameter.setMetadataParameterType(
                    DomainHelper.getInstance().getComboboxCd((Combobox) getFellow("cbParamType")));
            metadataParameter.setParamDatatype(
                    DomainHelper.getInstance().getComboboxCd((Combobox) getFellow("cbDatatype")));
            metadataParameter.setLanguageCd(
                    DomainHelper.getInstance().getComboboxCd((Combobox) getFellow("cbLanguage")));

            if (newEntry) {
                if (logger.isDebugEnabled())
                    logger.debug("Neuer Eintrag");

                // speichern
                hb_session.save(metadataParameter);

                if (codeSystemId > 0) {
                    String hqlV = "select distinct csev from CodeSystemEntityVersion csev join csev.codeSystemEntity ";
                    hqlV += "cse join cse.codeSystemVersionEntityMemberships csvem join csvem.codeSystemVersion csv join csv.codeSystem cs";

                    HQLParameterHelper parameterHelper = new HQLParameterHelper();
                    parameterHelper.addParameter("cs.", "id", codeSystemId);

                    // Parameter hinzufgen (immer mit AND verbunden)
                    hqlV += parameterHelper.getWhere("");
                    logger.debug("HQL: " + hqlV);

                    // Query erstellen
                    org.hibernate.Query qV = hb_session.createQuery(hqlV);

                    // Die Parameter knnen erst hier gesetzt werden (bernimmt Helper)
                    parameterHelper.applyParameter(qV);

                    List<CodeSystemEntityVersion> csevList = qV.list();
                    Set<CodeSystemMetadataValue> csmvSet = new HashSet<CodeSystemMetadataValue>(0);
                    for (CodeSystemEntityVersion csev : csevList) {
                        CodeSystemMetadataValue csmv = new CodeSystemMetadataValue();
                        csmv.setMetadataParameter(metadataParameter);
                        csmv.setParameterValue("");
                        csmv.setCodeSystemEntityVersion(csev);
                        hb_session.save(csmv);
                        csmvSet.add(csmv);
                    }

                    metadataParameter.setCodeSystemMetadataValues(csmvSet);
                    hb_session.update(metadataParameter);
                }

                /*if(valueSetId > 0)
                {
                  String hqlV = "select distinct csev from CodeSystemEntityVersion csev join csev.conceptValueSetMemberships cvsm ";
                  hqlV += " join cvsm.valueSetVersion vsv join vsv.valueSet vs";
                        
                  HQLParameterHelper parameterHelper = new HQLParameterHelper();
                  parameterHelper.addParameter("vs.", "id", valueSetId);
                        
                  // Parameter hinzufgen (immer mit AND verbunden)
                  hqlV += parameterHelper.getWhere("");
                  logger.debug("HQL: " + hqlV);
                        
                  // Query erstellen
                  org.hibernate.Query qV = hb_session.createQuery(hqlV);
                        
                  // Die Parameter knnen erst hier gesetzt werden (bernimmt Helper)
                  parameterHelper.applyParameter(qV);
                        
                  List<CodeSystemEntityVersion> csevList = qV.list();
                  Set<ValueSetMetadataValue> vsmvSet = new HashSet<ValueSetMetadataValue>(0);
                  for (CodeSystemEntityVersion csev : csevList)
                  {
                    ValueSetMetadataValue vsmv = new ValueSetMetadataValue();
                    vsmv.setMetadataParameter(metadataParameter);
                    vsmv.setParameterValue("");
                    vsmv.setValuesetVersionId(valueSetId);
                    vsmv.setCodeSystemEntityVersion(csev);
                    hb_session.save(vsmv);
                    vsmvSet.add(vsmv);
                  }
                        
                  metadataParameter.setValueSetMetadataValues(vsmvSet);
                  hb_session.update(metadataParameter);
                }*/
            } else {
                hb_session.merge(metadataParameter);
            }

            hb_session.getTransaction().commit();
        } catch (Exception e) {
            hb_session.getTransaction().rollback();
            logger.error("Fehler in MetadatenDetails.java in onOkClicked(): " + e.getMessage());
            e.printStackTrace();

            error = true;

            Messagebox.show(e.getMessage());
        } finally {
            hb_session.close();
        }

        if (error == false) {
            this.setVisible(false);
            this.detach();

            if (updateListInterface != null)
                updateListInterface.update(metadataParameter, !newEntry);
        }

    } catch (Exception e) {
        // Fehlermeldung ausgeben
        logger.error("Fehler in MetadatenDetails.java: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:de.fhdo.gui.admin.modules.terminology.SysParamDetails.java

License:Apache License

public void onOkClicked() {
    // speichern mit Hibernate

    try {/*from   ww w  . j  av  a  2s .  c o  m*/
        if (logger.isDebugEnabled())
            logger.debug("Daten speichern");

        //sysParam.setDomainValueByModifyLevel(selectedModifyLevel);
        //attachment.getAttachment().setTechnicalTypeCd(selectedTechnicalType.getDomainCode());

        Session hb_session = HibernateUtil.getSessionFactory().openSession();
        hb_session.getTransaction().begin();
        try {

            if (newEntry) {
                hb_session.save(sysParam);
            } else {
                if (logger.isDebugEnabled())
                    logger.debug("Daten aktualisieren");

                hb_session.merge(sysParam);
            }

            hb_session.getTransaction().commit();
        } catch (Exception e) {
            hb_session.getTransaction().rollback();
            logger.error("Fehler in onOkClicked() bei hibernate: " + e.getMessage());
        } finally {
            hb_session.close();
        }

        this.setVisible(false);

        if (iUpdateListener != null) {
            iUpdateListener.update(sysParam, !newEntry);
        }

        this.detach();
    } catch (Exception e) {
        // Fehlermeldung ausgeben
        logger.error("Fehler in onOkClicked(): " + e.getMessage());
        e.printStackTrace();
        if (hb_sessionS != null)
            hb_sessionS.close();
    }
    if (hb_sessionS != null)
        hb_sessionS.close();
    //Executions.getCurrent().setAttribute("contactPerson_controller", null);
}

From source file:de.fhdo.gui.admin.modules.terminology.user.LizenzDetails.java

License:Apache License

public void onOkClicked() {
    // speichern mit Hibernate
    try {/*w w  w.  j av  a  2  s. co m*/
        if (logger.isDebugEnabled())
            logger.debug("Daten speichern");

        if (newEntry) {
            if (licencedUser.getCodeSystemVersion() == null
                    || licencedUser.getCodeSystemVersion().getVersionId() == null
                    || licencedUser.getCodeSystemVersion().getVersionId().longValue() == 0) {
                Messagebox.show("Bitte whlen Sie ein Codesystem aus.");
                return;
            }
        }

        // Datumsangaben speichern
        if (showValidFrom == false)
            licencedUser.setValidFrom(null);
        if (showValidTo == false)
            licencedUser.setValidTo(null);

        // Lizenz-Typ
        if (showLicenceType) {
            try {
                Combobox cb = (Combobox) getFellow("comboLicenceType");
                licencedUser.setLicenceType((LicenceType) cb.getSelectedItem().getValue());
                logger.debug("Licencetype: " + licencedUser.getLicenceType().getId() + ", "
                        + licencedUser.getLicenceType().getTypeTxt());
            } catch (Exception e) {
            }
        } else {
            licencedUser.setLicenceType(null);
            logger.debug("Licencetype: null");
        }

        Session hb_session = HibernateUtil.getSessionFactory().openSession();

        try {
            hb_session.getTransaction().begin();
            if (newEntry) {
                if (logger.isDebugEnabled())
                    logger.debug("Neuer Eintrag");

                licencedUser.setId(new LicencedUserId(licencedUser.getTermUser().getId(),
                        licencedUser.getCodeSystemVersion().getVersionId()));

                hb_session.save(licencedUser);
            } else {
                hb_session.merge(licencedUser);
            }

            hb_session.getTransaction().commit();
        } catch (Exception e) {
            logger.error("Fehler in LizenzDetails.java (onOkClicked()): " + e.getMessage());
        } finally {
            hb_session.close();
        }

        this.setVisible(false);
        this.detach();

        if (updateListInterface != null)
            updateListInterface.update(licencedUser, !newEntry);

    } catch (Exception e) {
        // Fehlermeldung ausgeben
        logger.error("Fehler in DomainDetails.java: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:de.fhdo.gui.main.masterdata.UserDetails.java

License:Apache License

public void onOkClicked() {
    // speichern mit Hibernate
    try {/*from   w w  w. ja v  a  2s  .co  m*/
        if (logger.isDebugEnabled())
            logger.debug("Daten speichern");

        Session hb_session = HibernateUtil.getSessionFactory().openSession();
        hb_session.getTransaction().begin();

        try {
            hb_session.merge(user);
            hb_session.getTransaction().commit();
        } catch (Exception e) {
            hb_session.getTransaction().rollback();
            logger.debug("Fehler in UserDetails.java @ onOkClicked() innerCatch: " + e.getMessage());
        }

        hb_session.close();

        this.setVisible(false);
        this.detach();

        if (updateListInterface != null)
            updateListInterface.update(user, true);

    } catch (Exception e) {
        // Fehlermeldung ausgeben
        logger.debug("Fehler in UserDetails.java @ onOkClicked() outerCatch: " + e.getMessage());
        if (hb_sessionS != null)
            hb_sessionS.close();
    }
    if (hb_sessionS != null)
        hb_sessionS.close();
}

From source file:de.fhdo.terminologie.db.DBSysParam.java

License:Apache License

/**
 * Speichert einen Parameter in der Datenbank.
 *
 *
 * @param Parameter der Parameter//from ww  w .  j a  v  a2  s  . com
 * @return String mit Fehlermeldung oder leer bei Erfolg
 */
public String setValue(SysParam Parameter) {
    String ret = "";

    Session hb_session = HibernateUtil.getSessionFactory().openSession();

    try {
        hb_session.getTransaction().begin();
        applyDatatype(Parameter);

        hb_session.merge(Parameter);
        hb_session.getTransaction().commit();
    } catch (Exception ex) {
        ret = "Fehler bei 'setValue(): " + ex.getLocalizedMessage();
        ex.printStackTrace();
    } finally {
        hb_session.close();
    }

    return ret;
}

From source file:de.fhdo.terminologie.helper.SysParameter.java

License:Apache License

/**
 Speichert einen Parameter in der Datenbank.
        /*from w  ww.ja  v a 2  s  .c o  m*/
        
 @param Parameter der Parameter
 @return String mit Fehlermeldung oder leer bei Erfolg
 */
public String setValue(SysParam Parameter) {
    String ret = "";

    Session hb_session = HibernateUtil.getSessionFactory().openSession();
    hb_session.getTransaction().begin();

    try {
        hb_session.merge(Parameter);
    } catch (Exception ex) {
        ret = "Fehler bei 'setValue(): " + ex.getLocalizedMessage();
        ex.printStackTrace();
    }

    hb_session.getTransaction().commit();
    hb_session.close();

    return ret;
}