Example usage for org.hibernate Session createQuery

List of usage examples for org.hibernate Session createQuery

Introduction

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

Prototype

@Override
    org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);

Source Link

Usage

From source file:bank.DAO.CardDAO.java

public List<Card> listCard() {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   w ww. j a  v a2s .c  om*/
    List<Card> result = session.createQuery("from Card order by number").list();
    session.getTransaction().commit();
    return result;
}

From source file:bank.DAO.ClientsDAO.java

public List<Clients> listClients() {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   w w  w  . ja v  a2s .co m*/
    List<Clients> result = session.createQuery("from Clients order by name").list();
    session.getTransaction().commit();
    return result;
}

From source file:bank.DAO.CurrenciesDAO.java

public List<Currencies> listCurrencies() {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*w  w  w .ja v  a  2  s  . c o  m*/
    List<Currencies> result = session.createQuery("from Currencies order by id").list();
    session.getTransaction().commit();
    return result;
}

From source file:bank.DAO.OperationsDAO.java

public List<Operations> listOperations() {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w  w w .j a  v  a2 s. c o  m
    List<Operations> result = session.createQuery("from Operations order by for_id").list();
    session.getTransaction().commit();
    return result;
}

From source file:basedistribuida.connection.HibernateSession.java

protected <T> List<T> getAll(Class<T> clazz) {
    Session session = sessionFactory.openSession();
    List<T> generics;//from   ww  w.  j  a v  a 2 s  .c o  m
    try {
        session.beginTransaction();
        // UPDATED: Create CriteriaBuilder
        CriteriaBuilder builder = session.getCriteriaBuilder();

        // UPDATED: Create CriteriaQuery
        CriteriaQuery<T> criteria = builder.createQuery(clazz);

        // UPDATED: Specify criteria root
        criteria.from(clazz);

        // UPDATED: Execute query
        generics = session.createQuery(criteria).getResultList();

        session.getTransaction().commit();
    } finally {
        session.close();
    }
    return generics;
}

From source file:baza.Broker.java

public ArrayList<Lekar> vratiSveLekare() {
    Session session = Test.getSessionFactory().openSession();
    ArrayList<Lekar> lista = null;
    try {/*from   w ww .  j  av  a2s .co  m*/

        session.beginTransaction();
        Query q = session.createQuery("from Lekar");
        lista = (ArrayList<Lekar>) q.list();
        session.getTransaction().commit();
    } catch (HibernateException hibernateException) {
        session.getTransaction().rollback();
    } finally {
        session.close();
    }
    return lista;
}

From source file:baza.Broker.java

public List<Pacijent> vratiSvePacijente() {
    Session session = Test.getSessionFactory().openSession();
    List<Pacijent> lista = null;
    try {//from   www. j  a  v  a 2 s  .  co  m

        session.beginTransaction();
        Query q = session.createQuery("from Pacijent");
        lista = (ArrayList<Pacijent>) q.list();
        session.getTransaction().commit();
    } catch (HibernateException hibernateException) {
        session.getTransaction().rollback();
    } finally {
        session.close();
    }
    return lista;
}

From source file:baza.Broker.java

public ArrayList<Opstina> vratiOpstine() {
    Session session = Test.getSessionFactory().openSession();
    ArrayList<Opstina> opstine = null;
    try {/*from  w w  w.j  a  va2 s  .c  om*/

        session.beginTransaction();
        Query q = session.createQuery("from Opstina");
        opstine = (ArrayList<Opstina>) q.list();
        session.getTransaction().commit();
    } catch (HibernateException hibernateException) {
        session.getTransaction().rollback();
    } finally {
        session.close();
    }
    return opstine;
}

From source file:baza.Broker.java

public ArrayList<Tippregleda> vratiTipovePregleda() {
    Session session = Test.getSessionFactory().openSession();
    ArrayList<Tippregleda> tipovi = null;
    try {/*w w w . j a v a 2 s.c om*/

        session.beginTransaction();
        Query q = session.createQuery("from Tippregleda");
        tipovi = (ArrayList<Tippregleda>) q.list();
        session.getTransaction().commit();
    } catch (HibernateException hibernateException) {
        session.getTransaction().rollback();
    } finally {
        session.close();
    }
    return tipovi;
}

From source file:bazydanych.CRUDTest.java

private Samochod[] readCars() {
    Session session = factory.openSession();
    Transaction tx = null;//from ww  w.  j av a2 s  .c  o  m
    Samochod[] retList = null;
    try {
        tx = session.beginTransaction();
        List cars = session.createQuery("FROM Samochod").list();
        int s = cars.size();
        retList = new Samochod[s];
        for (int i = 0; i < s; i++) {
            retList[i] = (Samochod) cars.get(i);
        }
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null) {
            tx.rollback();
        }
        e.printStackTrace();
        fail();
    } finally {
        session.close();
    }
    return retList;
}