Example usage for org.hibernate Query list

List of usage examples for org.hibernate Query list

Introduction

In this page you can find the example usage for org.hibernate Query list.

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:automatedbillingsoftware_DA.Templete_DA.java

public Templete fetchTempleteByName(String tempName) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Templete where status=:status and name LIKE:name");
    query.setParameter("status", 1);
    query.setParameter("name", tempName);
    List<Templete> templeteList = (List<Templete>) query.list();
    beginTransaction.commit();// ww w . ja v a 2 s  .c om
    session.close();

    return templeteList != null && templeteList.size() > 0 ? templeteList.get(0) : null;
}

From source file:automatedbillingsoftware_DA.User_DA.java

public List<Users> fetchAllUser(Users users) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Users where status=:status");
    query.setParameter("status", 1);

    List<Users> list = (List<Users>) query.list();
    //   session.saveOrUpdate(users);
    beginTransaction.commit();/*from w ww  . j  a va 2 s . c  o  m*/
    //  return users;
    return list;
}

From source file:automatedbillingsoftware_DA.User_DA.java

public Users fetchUserById(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Users where status=:status and userid=:id");
    query.setParameter("status", 1);
    query.setParameter("userid", id);
    List<Users> list = (List<Users>) query.list();
    //   session.saveOrUpdate(users);
    beginTransaction.commit();//from w  w w  .  ja  v a2 s.  c  o  m
    //  return users;
    return (Users) list.get(0);
}

From source file:Baari.DbAccess.java

public List haeKannasta(String hql) {
    if (!alustettu) {
        alustaHibernate();//  w  ww. ja  va2s. com
    }
    Session session = alustaSessio();
    Query query = session.createQuery(hql);
    List list = query.list();
    //   closeConnection();
    return list;

}

From source file:backend.api.FinanceManagement.java

public List<Users> getAllUsers() // ok
{
    Session s = sf.openSession();//from  www  . j av a  2 s . com
    try {

        Query query = s.createQuery("select u from Users u");

        List<Users> users = query.list();
        if (users.isEmpty() || users.size() == 0)
            return null;
        return users;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }

}

From source file:backend.api.FinanceManagement.java

public Users getUser(int idUser) // ok
{
    Session s = sf.openSession();/*from   ww  w  .jav a  2  s .co m*/
    try {

        Query q = s.createQuery("select u from Users u where " + idUser + "=u.idusers");
        List<Users> result = q.list();
        if (result.isEmpty() || result.size() == 0)
            return null;
        return (Users) result.get(0);

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }

}

From source file:backend.api.FinanceManagement.java

public List<Users> getUsers(int IdGroup) //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {/*from   w  w w.  j  ava 2 s.  c om*/
        String hql = "select new backend.core.model.Users(u.idusers, u.name, u.surname, u.password, u.salt, u.hired, u.last_login) "
                + "from Users u join u.Groups g where g.idgroups in (:idGroup)";
        Query q = s.createQuery(hql);
        q.setParameter("idGroup", IdGroup);

        List<Users> result = q.list();

        if (result.isEmpty() || result.size() == 0)
            return null;
        return result;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }
}

From source file:backend.api.FinanceManagement.java

public List<Groups> getGroup() //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//from  w w  w .jav a2s . com

        Query q = s.createQuery("select g from Groups g");
        List<Groups> result = q.list();
        if (result.isEmpty() || result.size() == 0)
            return null;
        return result;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }
}

From source file:backend.api.FinanceManagement.java

public List<FinanceRegister> getFinanceRegisterRecords() //  ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//from w  w w .  ja  v a 2 s.  c om

        Query q = s.createQuery("select f from FinanceRegister f");
        List<FinanceRegister> result = q.list();
        if (result.isEmpty() || result.size() == 0)
            return null;
        return result;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }
}

From source file:backend.api.Statistics.java

public List<Monitoring> getRecords() {
    Session s = sf.openSession();/*w  ww  .  j  a  v  a  2s  .  co  m*/
    try {

        Query query = s.createQuery("select m from Monitoring m");

        List<Monitoring> monitor = query.list();
        if (monitor.isEmpty() || monitor.size() == 0)
            return null;
        return monitor;

    } finally {
        s.close();
    }
}