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:CitySearch.java

public City findCityByLocId(int locId) {
    Session sess = null;//from   w  ww .ja  v  a2 s  . co m
    City city = new City();
    try {
        sess = NewHibernateUtil.currentSession();
        Transaction tx = sess.beginTransaction();
        //sql query to find the row corresponding to location id
        String hql = "select * FROM Country WHERE locId=" + String.valueOf(locId);
        Query query = sess.createSQLQuery(hql).addEntity(City.class);

        List results = query.list();
        System.out.println(String.valueOf(results.size()));
        for (int i = 0; i < results.size(); i++) {
            city = ((City) results.get(i));
            System.out.println(((City) results.get(i)).country);
        }

        tx.commit();
        //sess.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return city;
}

From source file:GetMovDetails.java

protected int getDetails(String movname) {
    Configuration configuration = new Configuration();
    configuration.configure();/*from   ww  w.  ja  v  a2s.c  om*/
    serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    Session session = new Configuration().configure().buildSessionFactory(serviceRegistry).openSession();

    Transaction tx = null;
    try {
        tx = session.beginTransaction();
        String hql = "FROM GS_Movie m where m.name=:movname";
        Query query = session.createQuery(hql);
        query.setParameter("movname", movname);
        List results = query.list();
        GS_Movie gS_Movie = (GS_Movie) results.iterator().next();
        name = gS_Movie.getName();
        movid = gS_Movie.getMovid();
        plot = gS_Movie.getPlot();
        year = String.valueOf(gS_Movie.getYear());
        dir = gS_Movie.getDirector();
        genre = gS_Movie.getGenre();
        prod = gS_Movie.getProducer();
        cast = gS_Movie.getCast();
        //Update mov details
        System.out.println(name);
        System.out.println(movid);
        System.out.println(plot);
        System.out.println(year);
        System.out.println(dir);
        System.out.println(genre);
        System.out.println(prod);
        System.out.println(cast);

        result = 1;

    } catch (HibernateException e) {
        if (tx != null)
            tx.rollback();
        e.printStackTrace();
    } finally {
        session.close();
        return result;
    }
}

From source file:PeriodoJefeObraEnObra.java

public static List queryPeriodoJefeObraEnObra(PersistentSession session, String condition, String orderBy)
         throws PersistentException {
     StringBuffer sb = new StringBuffer("From PeriodoJefeObraEnObra as PeriodoJefeObraEnObra");
     if (condition != null)
         sb.append(" Where ").append(condition);
     if (orderBy != null)
         sb.append(" Order By ").append(orderBy);
     try {//www . j a  va 2  s.  co m
         Query query = session.createQuery(sb.toString());
         return query.list();
     } catch (Exception e) {
         e.printStackTrace();
         throw new PersistentException(e);
     }
 }

From source file:PeriodoJefeObraEnObra.java

public static List queryPeriodoJefeObraEnObra(PersistentSession session, String condition, String orderBy,
         org.hibernate.LockMode lockMode) throws PersistentException {
     StringBuffer sb = new StringBuffer("From PeriodoJefeObraEnObra as PeriodoJefeObraEnObra");
     if (condition != null)
         sb.append(" Where ").append(condition);
     if (orderBy != null)
         sb.append(" Order By ").append(orderBy);
     try {/*from   w w w . j  a  v a  2s .c  o  m*/
         Query query = session.createQuery(sb.toString());
         query.setLockMode("PeriodoJefeObraEnObra", lockMode);
         return query.list();
     } catch (Exception e) {
         e.printStackTrace();
         throw new PersistentException(e);
     }
 }

From source file:Bazica.java

public User getUserByName(String email) {
    Query query = session.createQuery("from User where email=:email");
    query.setParameter("email", email);
    List<User> list = query.list();
    if (list.size() == 0)
        return null;

    return list.get(0);
}

From source file:LineaAlbaran.java

public static List queryLineaAlbaran(PersistentSession session, String condition, String orderBy)
         throws PersistentException {
     StringBuffer sb = new StringBuffer("From LineaAlbaran as LineaAlbaran");
     if (condition != null)
         sb.append(" Where ").append(condition);
     if (orderBy != null)
         sb.append(" Order By ").append(orderBy);
     try {//w  ww.j a va  2  s.c om
         Query query = session.createQuery(sb.toString());
         return query.list();
     } catch (Exception e) {
         e.printStackTrace();
         throw new PersistentException(e);
     }
 }

From source file:LineaAlbaran.java

public static List queryLineaAlbaran(PersistentSession session, String condition, String orderBy,
         org.hibernate.LockMode lockMode) throws PersistentException {
     StringBuffer sb = new StringBuffer("From LineaAlbaran as LineaAlbaran");
     if (condition != null)
         sb.append(" Where ").append(condition);
     if (orderBy != null)
         sb.append(" Order By ").append(orderBy);
     try {/*from   w w  w  . j  a  va 2s.  c om*/
         Query query = session.createQuery(sb.toString());
         query.setLockMode("LineaAlbaran", lockMode);
         return query.list();
     } catch (Exception e) {
         e.printStackTrace();
         throw new PersistentException(e);
     }
 }

From source file:EmpleadoObra.java

public static List queryEmpleadoObra(PersistentSession session, String condition, String orderBy)
         throws PersistentException {
     StringBuffer sb = new StringBuffer("From EmpleadoObra as EmpleadoObra");
     if (condition != null)
         sb.append(" Where ").append(condition);
     if (orderBy != null)
         sb.append(" Order By ").append(orderBy);
     try {/*w w w. j  av a2  s  .c  om*/
         Query query = session.createQuery(sb.toString());
         return query.list();
     } catch (Exception e) {
         e.printStackTrace();
         throw new PersistentException(e);
     }
 }

From source file:EmpleadoObra.java

public static List queryEmpleadoObra(PersistentSession session, String condition, String orderBy,
         org.hibernate.LockMode lockMode) throws PersistentException {
     StringBuffer sb = new StringBuffer("From EmpleadoObra as EmpleadoObra");
     if (condition != null)
         sb.append(" Where ").append(condition);
     if (orderBy != null)
         sb.append(" Order By ").append(orderBy);
     try {/*from w ww  .  j  a v  a 2s  . c o m*/
         Query query = session.createQuery(sb.toString());
         query.setLockMode("EmpleadoObra", lockMode);
         return query.list();
     } catch (Exception e) {
         e.printStackTrace();
         throw new PersistentException(e);
     }
 }

From source file:JefeDeObra.java

public static List queryJefeDeObra(PersistentSession session, String condition, String orderBy)
         throws PersistentException {
     StringBuffer sb = new StringBuffer("From JefeDeObra as JefeDeObra");
     if (condition != null)
         sb.append(" Where ").append(condition);
     if (orderBy != null)
         sb.append(" Order By ").append(orderBy);
     try {/*  w  ww .j  av  a 2s.  c  o  m*/
         Query query = session.createQuery(sb.toString());
         return query.list();
     } catch (Exception e) {
         e.printStackTrace();
         throw new PersistentException(e);
     }
 }