Example usage for org.hibernate Session update

List of usage examples for org.hibernate Session update

Introduction

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

Prototype

void update(Object object);

Source Link

Document

Update the persistent instance with the identifier of the given detached instance.

Usage

From source file:com.cantor.ipplan.server.ProfileServiceImpl.java

License:Open Source License

@Override
public PUserWrapper setUserData(PUserWrapper data, int joinAction) throws Exception {
    PUser user = checkLogin();/*w  ww  . ja va2  s . c  o  m*/

    SessionFactory sessionFactory = (SessionFactory) getServletContext().getAttribute("sessionFactory");
    Session session = sessionFactory.openSession();
    try {
        Transaction tx = session.beginTransaction();
        try {
            session.update(user);

            user.setPuserLogin(data.puserLogin);
            user.setPuserEmail(data.puserEmail);
            user.setPuserTarif(data.puserTarif);
            user.setPuserTaxtype(data.puserTaxtype);
            user.setPuserTaxpercent(data.puserTaxpercent);

            // ? ??-
            if (data.puserBoss != 0 && user.getPuserTarif() <= 0)
                throw new Exception(
                        "    ,   ? ? "
                                + " ??- ??    (? ? ).");
            user.setPuserBoss(data.puserBoss);

            // ? ?? 

            // ?  
            for (PUser child : user.getChildren()) {
                if (!containsChildren(child, data.children)) {
                    user.getChildren().remove(child);
                    child.setOwner(null);
                    session.update(child);
                }
            }
            // ? 
            for (PUserWrapper u : data.children)
                if (!u.tempflag) {
                    PUser pu = getUserByEmail(session, u.puserEmail);
                    sendMessageToUser(session, user, pu,
                            "  ?  , "
                                    + " ?   "
                                    + user.getFullName(),
                            Messages.MT_JOIN_TO_OWNER);
                }
            // ? ?
            if (joinAction != 0) {
                if (joinAction == 1) {
                    PUser own = (PUser) session.load(PUser.class, data.lastSystemMessage.sender.puserId);
                    user.setOwner(own);
                }
                //  ??
                deleteMessage(session, data.lastSystemMessage.messageId);
            }
            tx.commit();

            return user.toClient();
        } catch (Exception e) {
            tx.rollback();
            Ipplan.error(e);
            throw new Exception(" ? ? ? "
                    + user.getFullName() + ": " + e.getMessage());
        }
    } finally {
        session.close();
    }
}

From source file:com.carlos.projects.billing.dao.hibernate.HibernateDAO.java

License:Open Source License

public void update(T entity) {
    Session session = getSession();
    session.update(entity);
}

From source file:com.castillo.hibernate.Guardar.java

public void actualizar(int id, String nombre, String password) {

    Session sesion = Utilidades.getSessionFactory().openSession();
    // primer paso: Empezar una sesion

    sesion.getTransaction().begin();/* ww w.  j a  v a  2s .c  om*/
    sesion.update(new Usuario3(id, nombre, password));

    sesion.getTransaction().commit();
    System.out.println("Se actualizo el registro");
    sesion.close();

}

From source file:com.ccsna.ccsna.AgencyModel.java

public boolean update(int id, String fullName, String streetAddress, String aptNo, String city, String state,
        Long zipcode, Long privateContactNo, String webUrl, String mission, String hours_Of_Operation,
        String required_Verification, String boardPostions, String status, String emailAddress,
        Long publicPhoneNo, String updatedBy, Set counties, String[] services) {

    Session session = HibernateUtil.sessionFactory.openSession();
    Transaction tx = null;/*w  ww .j  av a2 s  .  co m*/
    long value = 0l;
    try {
        tx = session.beginTransaction();
        agency = findById(id);
        if (agency == null) {
            log.warn("could not find agency with id:" + id);
            return false;
        } else {
            log.info("beginning update ... ");
            if (!Validation.checkNullity(fullName)) {
                agency.setFullname(fullName);
            }
            if (!Validation.checkNullity(streetAddress)) {
                agency.setStreetAddress(streetAddress);
            }
            if (!Validation.checkNullity(aptNo)) {
                agency.setApartmentNo(aptNo);
            }
            if (!Validation.checkNullity(city)) {
                agency.setCity(city);
            }
            if (!Validation.checkNullity(state)) {
                agency.setState(state);
            }
            if (zipcode != null && (zipcode.compareTo(value)) == 1) {
                agency.setZipcode(zipcode);
            }
            if (privateContactNo != null && (privateContactNo.compareTo(value)) == 1) {
                agency.setPrivateContactNumber(privateContactNo);
            }
            if (!Validation.checkNullity(webUrl)) {
                agency.setWebsiteAddress(webUrl);
            }
            if (!Validation.checkNullity(mission)) {
                agency.setMission(mission);
            }
            if (!Validation.checkNullity(hours_Of_Operation)) {
                agency.setHoursOfOperation(hours_Of_Operation);
            }
            if (!Validation.checkNullity(required_Verification)) {
                agency.setRequiredVerification(required_Verification);
            }
            if (!Validation.checkNullity(boardPostions)) {
                agency.setBoardPositions(boardPostions);
            }
            if (!Validation.checkNullity(status)) {
                agency.setStatus(status);
            }
            if (!Validation.checkNullity(emailAddress)) {
                agency.setEmailAddress(emailAddress);
            }
            if (publicPhoneNo != null && (publicPhoneNo.compareTo(value)) == 1) {
                agency.setPublicContactNumber(publicPhoneNo);
            }
            agency.setUpdatedBy(updatedBy);
            agency.setDateUpdated(new Date());
            //clear all the counties
            agency.getCounties().clear();

            //add all the counties
            if (counties != null && !counties.isEmpty()) {
                agency.setCounties(counties);
            }
        }
        session.update(agency);
        tx.commit();
    } catch (Exception he) {
        if (tx != null) {
            log.info("unable to update agency with " + id);
            tx.rollback();
            return false;
        }
    } finally {
        session.close();
    }
    return true;
}