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.apt.facade.StudentFacade.java

public boolean updateStudent(Student student) {
    Session session = null;
    Transaction trans = null;//from  www. j a  v  a2s  . c om
    try {
        int studentID = student.getStudentId();
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        Student student1 = (Student) session.get(Student.class, studentID);
        student1.setBatch(student.getBatch());
        student1.setPassword(student.getPassword());
        student1.setStudentName(student.getStudentName());

        session.update(student1);

        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
        return false;
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }
    return true;
}

From source file:com.apt.facade.SubjectFacade.java

public void updateSubject(int subjectID, String name) {
    Session session = null;
    Transaction trans = null;/*from w  w w  .j  a v  a  2s . c om*/

    try {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        Subject subject = (Subject) session.get(Subject.class, subjectID);
        subject.setSubjectName(name);
        session.update(subject);

        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }

}

From source file:com.apt.facade.SubjectFacade.java

public void updateSubject(Subject subject) {
    Session session = null;
    Transaction trans = null;/*from w  w w. j ava2s  . c  om*/

    try {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        session.update(subject);

        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }
}

From source file:com.artech.prototype2.saver.dao.AbstractDao.java

public void update(AbstractSUBD db, Type entity) {
    Session session = null;
    try {//from   www. j  a v  a2  s. com
        session = HibernateUtil.getSessionFactory(db).openSession();
        session.beginTransaction();
        session.update(entity);
        session.getTransaction().commit();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }
}

From source file:com.asociate.dao.UsuarioDAO.java

/**
 *
 * @param user/*from  ww  w.  ja v a2 s  . c  o  m*/
 */
public void actualizar(Usuario user) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();

    try {
        sesion.update(user);

    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
}

From source file:com.assignment.elance.modelManager.JobManager.java

public void changeStatus(int jobId, String status) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   www .j a v a  2s  .  c  o m

    Job job = (Job) session.load(Job.class, new Integer(jobId));
    job.setJob_status(status);

    session.update(job);
    session.getTransaction().commit();

}

From source file:com.assignment.elance.modelManager.JobManager.java

public void setStartAndEndDate(int jobId, long hrs, float price) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  ww w .j  a va  2s. co m

    Job job = (Job) session.load(Job.class, new Integer(jobId));
    Date currentDate = new Date();
    job.setStart_date(currentDate);
    long tempDate = currentDate.getTime() + hrs * 60 * 60 * 1000;
    job.setEnd_date(new Date(tempDate));
    job.setBidded_price(price);
    session.update(job);
    session.getTransaction().commit();
}

From source file:com.assignment.elance.modelManager.MilestoneManager.java

public void changeStatus(int milestone_id, int status) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//  ww  w.j  a va 2s  . co  m

    Milestone milestone = (Milestone) session.load(Milestone.class, new Integer(milestone_id));
    milestone.setMilestone_status(status);
    session.update(milestone);
    session.getTransaction().commit();
}

From source file:com.atlanta.educati.daoImp.ApoderadoDaoImp.java

@Override
public int update(Apoderado x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;/*ww w . java  2 s . co  m*/

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}

From source file:com.atlanta.educati.daoImp.CursoDaoImp.java

@Override
public int update(Curso x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;//w  ww  .  ja  v  a2  s .com

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}