Example usage for org.hibernate Session load

List of usage examples for org.hibernate Session load

Introduction

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

Prototype

void load(Object object, Serializable id);

Source Link

Document

Read the persistent state associated with the given identifier into the given transient instance.

Usage

From source file:TestConnectionMySQL.java

/**
 * @param args the command line arguments
 *//*from   www. j a  v a  2  s . c o m*/
public static void main(String[] args) {
    // TODO code application logic here

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();
    Long id = (Long) session.load(Usuario.class, "ferrarihe");
    transaction.commit();

}

From source file:$.DefaultDAO.java

License:Open Source License

public <ENTITY extends IdentifiedEntityInterface> boolean delete(Class<ENTITY> clazz, Long id) {
        if (softDelete) {
            throw new UnsupportedOperationException("Physical delete operation forbidden");
        }//from   w w  w  .  jav  a2 s  .  co m

        if (id == null) {
            throw new IllegalArgumentException("Invalid value for entity ID provided:[NULL]");
        }

        if (!exists(clazz, id)) {
            // TODO add logging
            return false;
        }

        Session session = getSession();
        session.delete(session.load(clazz, id));
        return true;
    }

From source file:Activity.activityDelete.java

public static void activityDeleteById(Integer id) {
    Session session;
    Activity activity;//from   w w  w . java 2s  . co  m
    session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();
    activity = (Activity) session.load(Activity.class, id);
    session.delete(activity);
    //This makes the pending delete to be done
    session.getTransaction().commit();
}

From source file:Activity.activityDelete.java

public static void activityReportDeleteById(Integer actid) {
    Session session;
    ActivityReport activityReport;/*from w w w . jav  a 2 s.  co  m*/
    session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();
    activityReport = (ActivityReport) session.load(ActivityReport.class, actid);
    session.delete(activityReport);
    //This makes the pending delete to be done
    session.getTransaction().commit();

}

From source file:AdminSystemClasses.AtmDB.java

public static BankATM addAtm(ATMaddmoddel atm) throws Exception {

    Session sf = DB.getSession();
    Transaction tx = sf.beginTransaction();

    Criteria cr = sf.createCriteria(BankATM.class);
    cr.add(Restrictions.eq("id", atm.getAtmId()));

    if (cr.list().isEmpty()) {
        BankBranch bb = (BankBranch) sf.load(BankBranch.class, atm.getBranchid());
        BankATM myatm = new BankATM();
        myatm.setId(atm.getAtmId());// w  w w.j  a  v a  2 s  . co m
        myatm.setBankbranch(bb);
        myatm.setTill(atm.getTill());
        sf.save(myatm);
        tx.commit();
        return myatm;
    }

    return null;
}

From source file:AdminSystemClasses.AtmDB.java

public static BankATM delete(DeleteATM atm) throws Exception {
    Session sf = DB.getSession();
    Transaction tx = sf.beginTransaction();

    Criteria cr = sf.createCriteria(BankATM.class);
    cr.add(Restrictions.eq("id", atm.getAtmId()));
    BankATM bank;/*from  w  ww. j av  a 2  s .com*/
    if (!cr.list().isEmpty()) {
        bank = (BankATM) sf.load(BankATM.class, atm.getAtmId());
        sf.delete(bank);
        tx.commit();
    } else {
        return null;
    }

    return bank;
}

From source file:AdminSystemClasses.AtmDB.java

public static boolean edit(EditATM edit) {

    Session sf = DB.getSession();
    Transaction tx = sf.beginTransaction();

    BankATM bank = new BankATM();

    BankBranch bb = (BankBranch) sf.load(BankBranch.class, edit.getBranchid());
    bank.setId(edit.getAtmId());/*from  w w w. j  ava 2s .c o m*/
    bank.setBankbranch(bb);
    if (edit.getTill().intValue() < 0) {
        return false;
    } else {
        bank.setTill(edit.getTill());
    }
    sf.saveOrUpdate(bank);
    tx.commit();
    return true;
}

From source file:angeldx.manager.EstudianteManager.java

public boolean eliminar(int id) {
    Session session = HibernateUtil.openSession();
    Transaction tx = null;/*from w ww  . j av a 2 s . c  om*/
    try {
        tx = session.beginTransaction();
        Estudiante est = (Estudiante) session.load(Estudiante.class, new Integer(id));
        session.delete(est);
        tx.commit();
    } catch (RuntimeException e) {
        if (tx != null) {
            tx.rollback();
        }
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
    return true;
}

From source file:appHibernateSebastianLeonte.Main.java

public static void eliminar() {
    SessionFactory session = SessionFactoryUtil.getSessionFactory();
    Session s = session.openSession();
    Transaction transaction = s.beginTransaction();
    System.out.println("Elimiando");
    Vuelos vuelos = (Vuelos) s.load(Vuelos.class, (String) "AB-BY-4811");
    s.delete(vuelos);// w  w w. j av a2 s . com
    transaction.commit();
    s.close();
    session.close();
}

From source file:appHibernateSebastianLeonte.Main.java

public static void modificar() {
    SessionFactory session = SessionFactoryUtil.getSessionFactory();
    Session s = session.openSession();
    Transaction transaction = s.beginTransaction();
    System.out.println("Modificando");
    Vuelos vuelos = (Vuelos) s.load(Vuelos.class, (String) "AB-BY-4811");
    vuelos.setProcedencia("Hola");
    s.update(vuelos);/*from   ww  w. j  av  a2 s . co  m*/
    s.save(vuelos);
    transaction.commit();
    s.close();
    session.close();
}