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:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java

License:Open Source License

@Override
public Item getItemById(Integer id) throws PigeException {

    PermissionHelper.checkBrowseInventoryPermission(getThreadLocalRequest());

    Transaction tx = null;//from w  w  w . j  a  va  2s  . c o m
    Session session = null;
    Item item = null;

    try {
        session = PigeHibernateUtil.openSession();
        tx = session.beginTransaction();
        item = (Item) session.load(Item.class, id);
        tx.commit();

        if (item == null) {
            throw new NonExistantItemException();
        }

        logger.debug("Rcupration russie!");
    } catch (Exception hex) {
        logger.error(hex);
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }

    return item;
}

From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java

License:Open Source License

@Override
public void deleteItem(List<Integer> ids) throws PigeException {

    PermissionHelper.checkInventoryManagementPermission(getThreadLocalRequest());

    logger.debug("Suppression des items [ids = " + ids.toString() + "] ...");

    Session session = null;
    Transaction tx = null;//from   www  .j  a v  a 2 s.  c  o  m

    try {
        session = PigeHibernateUtil.openSession();
        tx = session.beginTransaction();

        for (Integer id : ids) {
            Item item = (Item) session.load(Item.class, id);
            session.delete(item);
        }

        tx.commit();
        logger.debug("Suppression russie!");
    } catch (Exception hex) {
        logger.error(hex);
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java

License:Open Source License

@Override
public void deleteMaintenance(List<Integer> ids) throws PigeException {

    PermissionHelper.checkInventoryManagementPermission(getThreadLocalRequest());

    logger.debug("Suppression des maintenances [ids = " + ids.toString() + "] ...");

    Session session = null;
    Transaction tx = null;//w w w. j  a  v a2 s  .  c om

    try {
        session = PigeHibernateUtil.openSession();
        tx = session.beginTransaction();

        for (Integer id : ids) {
            Maintenance maintenance = (Maintenance) session.load(Maintenance.class, id);
            session.delete(maintenance);
        }

        tx.commit();
        logger.debug("Suppression russie!");
    } catch (Exception hex) {
        logger.error(hex);
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:Category.categoryDelete.java

public static void categoryDeleteById(Integer catid) {
    Session session2;
    Category category;/*from   ww w .  j  a  v  a2  s. com*/
    session2 = HibernateUtil.getSessionFactory().openSession();
    session2.beginTransaction();
    category = (Category) session2.load(Category.class, catid);
    session2.delete(category);
    //This makes the pending delete to be done
    session2.getTransaction().commit();
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

public E load(final long id, final LockOptions lockOptions) {

    Session currentSession = getCurrentSession();
    Object result;/*from   ww  w  . j a  v a2  s  .com*/
    if (lockOptions == null) {
        result = currentSession.load(this.entityClass, id);
    } else {
        result = currentSession.load(this.entityClass, id, lockOptions);
    }
    return this.entityClass.cast(result);
}

From source file:ch.tatool.app.service.impl.ModuleDAO.java

License:Open Source License

/**
 * Deletes a module//from   w  w w . ja va 2s.  c  o m
 * 
 * @param module the module to load
 */
public void deleteModule(final ModuleInfoImpl moduleInfo) {
    getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) {
            // PENDING: can't hibernate figure this out on its own?
            // First delete all trials
            List<?> trialIds = session
                    .createQuery("select id from TrialImpl trial where trial.session.module.id = :id")
                    .setParameter("id", moduleInfo.getId()).list();
            for (Object o : trialIds) {
                TrialImpl trial = new TrialImpl();
                session.load(trial, (Long) o);
                session.delete(trial);
                //session.createQuery("delete TrialImpl trial where trial.id = :id").setParameter("id", o).executeUpdate();
            }
            session.flush();

            // then delete the sessions
            List<?> sessionIds = session
                    .createQuery("select id from ModuleSessionImpl session where session.module.id = :id")
                    .setParameter("id", moduleInfo.getId()).list();
            for (Object o : sessionIds) {
                ModuleSessionImpl s = new ModuleSessionImpl();
                session.load(s, (Long) o);
                session.delete(s);
            }

            // finally delete the module
            // Does not work because for some reason the module properties are not deleted in cascade...
            /*
            Query query = session.createQuery("delete from ModuleImpl module where module-id = :moduleId");
            query.setLong("moduleId", moduleInfo.getId());
            query.executeUpdate();
            */

            // and finally the module itself
            ModuleImpl module = loadModule(moduleInfo);
            session.delete(module);
            return null;
        }
    });
}

From source file:cl.model.dao.test.java

public static void main(String[] juan) {
    try {/*from   w ww . j  a  v a  2s  .  co  m*/
        Session sf = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction t = sf.beginTransaction();
        //Session session = sf.openSession();
        Productos pro = (Productos) sf.load(Productos.class, "114452");
        if (pro != null) {
            System.out.println("Nombre producto " + pro.getNombre());
        } else {
            System.out.println("No");
        }
        t.commit();
    } catch (Exception ex) {
        System.out.println("Error : " + ex.toString());
    }

}

From source file:cn.net.withub.demo.bootsec.hello.dao.impl.BaseDAOImpl.java

@Override
public void deleteByKey(Serializable id) {
    Session session = currentSession();
    session.delete(session.load(entityClass, id));
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

From source file:cn.net.withub.demo.bootsec.hello.dao.impl.BaseDAOImpl.java

@SuppressWarnings("unchecked")
@Override/*from  w w  w.  j  a v  a2  s .  c  om*/
public E findOne(Serializable id) {
    Session session = currentSession();
    return (E) session.load(entityClass, id);
}

From source file:cn.newtouch.model.TeacherTest.java

License:Open Source License

@Test
public void testLoad() {

    Session session = HibernateUtil.getSession();
    session.beginTransaction();//from w ww. j  ava  2s.co  m
    Teacher t = (Teacher) session.load(Teacher.class, 55);
    System.out.println(t.getName());
    session.getTransaction().commit();
    System.out.println(t.getClass());
    // 
}