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:bo.gaceta.rcb.dao.impl.TbInCiiuImpl.java

public List<TbInCiiu> listDivision(String idSeccion) throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*  www.  j  av  a2s .  co m*/
    session.flush();
    Query query = session
            .createQuery("SELECT e FROM TbInCiiu e WHERE e.idSeccion=:_txtBusca GROUP BY e.idDivision")
            .setParameter("_txtBusca", idSeccion);
    List<TbInCiiu> entities = query.list();
    session.getTransaction().commit();
    session.close();
    return entities;
}

From source file:bo.gaceta.rcb.dao.impl.TbInCiiuImpl.java

public List<TbInCiiu> listGrupo(String idDivision) throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*from w ww .j a v a 2  s  . c o  m*/
    session.flush();
    Query query = session
            .createQuery("SELECT e FROM TbInCiiu e WHERE e.idDivision=:_txtBusca GROUP BY e.idGrupo")
            .setParameter("_txtBusca", idDivision);
    List<TbInCiiu> entities = query.list();
    session.getTransaction().commit();
    session.close();
    return entities;
}

From source file:bo.gaceta.rcb.dao.impl.TbInCiiuImpl.java

public List<TbInCiiu> listClasebySeccion(String idSeccion) throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*from  ww w.  j  a v a 2  s .co m*/
    session.flush();
    Query query = session.createQuery("SELECT e FROM TbInCiiu e WHERE e.idSeccion=:_txtBusca")
            .setParameter("_txtBusca", idSeccion);
    List<TbInCiiu> entities = query.list();
    session.getTransaction().commit();
    session.close();
    return entities;
}

From source file:bo.gaceta.rcb.dao.impl.TbInCiiuImpl.java

public List<TbInCiiu> listClasebyDivision(String idDivision) throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();//from  w ww .  ja  v a2 s. c o  m
    session.flush();
    Query query = session.createQuery("SELECT e FROM TbInCiiu e WHERE e.idDivision=:_txtBusca")
            .setParameter("_txtBusca", idDivision);
    List<TbInCiiu> entities = query.list();
    session.getTransaction().commit();
    session.close();
    return entities;
}

From source file:bo.gaceta.rcb.dao.impl.TbInCiiuImpl.java

public List<TbInCiiu> listClasebyGroup(String idGrupo) throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();//from  w  w  w.ja  v  a 2s . co  m
    session.flush();
    Query query = session.createQuery("SELECT e FROM TbInCiiu e WHERE e.idGrupo=:_txtBusca")
            .setParameter("_txtBusca", idGrupo);
    List<TbInCiiu> entities = query.list();
    session.getTransaction().commit();
    session.close();
    return entities;
}

From source file:bo.gaceta.rcb.dao.impl.TbInCiiuImpl.java

public String desClase(String idClase) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();//from w  w  w.  ja v a2  s.  c om
    session.flush();
    Query query = session.createQuery("SELECT e FROM TbInCiiu e WHERE e.idClase=:_txtBusca")
            .setParameter("_txtBusca", idClase);
    TbInCiiu entities = (TbInCiiu) query.uniqueResult();
    session.getTransaction().commit();
    session.close();
    return entities.getClase();
}

From source file:bookstore.BookStoreManager.java

public void viewDetaiBook() {
    try {//  w w  w.j  a va 2 s.c om

        //Khoi tao session va bat dau lam viec voi session do
        Session session = sf.openSession();
        session.beginTransaction();

        //Nhap ma so cua cuon sach muon xem chi tiet
        Scanner sc = new Scanner(System.in);
        System.out.println("Input ISBM book want view: ");
        int isbm = sc.nextInt();

        //Viet cau lenh HQL  de tim cuon sach do
        Query query = session.createQuery("From Book where isbm = :isbm");
        //set parameter cho isbm la isbm duoc nhap vao tu ban phim
        query.setParameter("isbm", isbm);
        //Dua book tim duoc vao trong list book bang phuong thuc list();
        List<Book> list = query.list();

        //in ra thong tin cua cuon sach va chi tiet cua cuon sach do thong qua ham getBoodetail()
        for (Book book : list) {
            System.out.println("ISBM: " + book.getIsbm() + " - Name: " + book.getName() + " - Number page: "
                    + book.getBookdetail().getNumpage() + " - Publisher: "
                    + book.getBookdetail().getPublisher());
        }
        //Sau khi thuc hien xong cau truy van thi nen dong session do lai
        session.close();
    } catch (Exception e) {
    }
}

From source file:bookstore.BookStoreManager.java

public void removeOneToOne() throws IOException {
    try {/*from  www  . ja va  2 s  .  com*/
        //Tao 1 session va bat dau lam viec voi no
        Session session = sf.openSession();
        session.beginTransaction();

        //Nguoi dung se nhap ma so cuon sach can xoa
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Input isbm book want delete: ");
        int isbm = Integer.parseInt(input.readLine());

        //Viet cau lenh HQL de xoa chi tiet cua cuon sach do
        String hql = "delete from Bookdetail where isbm=:isbm";
        Query query = session.createQuery(hql);
        //Set parameter choi cau lenh vua viet
        query.setParameter("isbm", isbm);
        //moi thay doi nhu create, update , delete phai dung executeUpdate() de thuc hien

        query.executeUpdate();
        //sau khi xoa chi tiet cuon sach thi moi xoa duoc cuon sach do
        hql = "delete from Book where isbm=:isbm";
        query = session.createQuery(hql);
        query.setParameter("isbm", isbm);
        query.executeUpdate();

        session.getTransaction().commit();
        //sau khi xoa thi dong session lai
        session.close();
        System.out.println("Done");
    } catch (Exception e) {
    }
}

From source file:bookstore.BookStoreManager.java

public void viewBookOfAuthor() throws IOException {
    try {//from w w  w .j a v a 2 s  . c  o  m
        //Nhap ten tac gia do vao
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Input name author: ");
        String authorName = input.readLine();

        //tao session va bat dau lam viec voi session do
        Session session = sf.openSession();
        session.beginTransaction();

        //viet cau lenh hql de lay duoc tac gia vua tao
        Query query = session.createQuery("from Author where name = :name");
        //set parameter cho cau lenh HQL tren
        query.setParameter("name", authorName);
        //Dua tac gia vua tao vao 1 list tac gia bang phuong thuc list();
        List<Author> list = query.list();

        System.out.println("List Book of " + authorName + " is: ");
        //duyet ten nhung cuon sach cua tac gia do
        for (Author author : list) {
            Set<Book> setBook = author.getBooks();
            for (Book b : setBook) {
                System.out.println(b.toString());
            }
        }
        session.close();
        System.out.println("DONE");
    } catch (Exception e) {
        System.out.println("Error: " + e.getMessage());
    }
}

From source file:bookstore.BookStoreManager.java

public void viewAuthorOfBook() throws IOException {
    try {//from w  w w.j av  a  2 s .c o  m
        //Nhap ma cuon sach do vao
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Input isbm of book: ");
        int idbook = Integer.parseInt(input.readLine());
        //tao 1 session va bat dau lam viec voi session do
        Session session = sf.openSession();
        session.beginTransaction();

        //Viet cau lenh HQL de tim cuon sach theo ma cuon sach
        Query query = session.createQuery("from Book where isbm= :idbook");
        //Set parameter cho cau lenh tren
        query.setParameter("idbook", idbook);
        //dua ket qua cua cau lenh tren vao danh list book bang phuong thuc list()
        List<Book> list = query.list();
        System.out.println("List Author of Book is: ");
        //Duyet danh sachc cac tac gia cua cuon sach do bang phuong thuc getAuthor
        for (Book book : list) {
            Set<Author> setAuthors = book.getAuthors();
            for (Author a : setAuthors) {
                System.out.println(a.toString());
            }
        }
        //Dong session lai sau khi xong viec
        session.close();
        System.out.println("DONE");
    } catch (Exception e) {
        System.out.println("Error: " + e.getMessage());
    }
}